fgsl / doctrine-orm-module
Laminas 模块,提供 Doctrine ORM 功能
1.0.0
2020-02-07 16:58 UTC
Requires
- php: ^7.1
- doctrine/dbal: ^2.6.0
- doctrine/doctrine-module: ^3.0.1
- doctrine/orm: ^2.6.3
- laminas/laminas-hydrator: ^3.0.0
- laminas/laminas-mvc: ^3.1
- laminas/laminas-servicemanager: ^3.3
- laminas/laminas-stdlib: ^3.2.1
- symfony/console: ^3.3 || ^4.0 || ^5.0
Requires (Dev)
- doctrine/data-fixtures: ^1.2.1
- doctrine/migrations: ^1.5 || ^2.0
- laminas/laminas-console: ^2.6
- laminas/laminas-developer-tools: ^1.1
- laminas/laminas-i18n: ^2.7.3
- laminas/laminas-log: ^2.9
- laminas/laminas-modulemanager: ^2.7.2
- laminas/laminas-mvc-console: ^1.2
- laminas/laminas-serializer: ^2.8
- phpunit/phpunit: ^7.0.3
- squizlabs/php_codesniffer: ^2.7
Suggests
- doctrine/migrations: doctrine migrations if you want to keep your schema definitions versioned
- laminas/laminas-developer-tools: laminas-developer-tools if you want to profile operations executed by the ORM during development
- laminas/laminas-form: if you want to use form elements backed by Doctrine
This package is auto-updated.
Last update: 2024-09-08 03:21:44 UTC
README
这是 Laminas 的 Doctrine\DoctrineORMModule 的重构。
DoctrineORMModule 快速简单地集成 Doctrine 2 ORM 与 Laminas。
- Doctrine 2 ORM 支持
- 多个 ORM 实体管理器
- 多个 DBAL 连接
- 在 DBAL 连接中重用现有的 PDO 连接
安装
此模块的安装使用 composer。有关 composer 文档,请参阅 getcomposer.org。
composer require fgsl/doctrine-orm-module
然后,将 DoctrineModule
和 DoctrineORMModule
添加到您的 config/application.config.php
中,并创建目录 data/DoctrineORMModule/Proxy
,并确保您的应用程序有写入权限。
不使用 composer 的安装不受官方支持,并且需要您手动安装 composer.json
中列出的所有依赖项。
实体设置
要将您的实体注册到 ORM 中,请将以下元数据驱动程序配置添加到您的模块(合并)配置中,为每个实体命名空间
<?php return [ 'doctrine' => [ 'driver' => [ // defines an annotation driver with two paths, and names it `my_annotation_driver` 'my_annotation_driver' => [ 'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class, 'cache' => 'array', 'paths' => [ 'path/to/my/entities', 'another/path', ], ], // default metadata driver, aggregates all other drivers into a single one. // Override `orm_default` only if you know what you're doing 'orm_default' => [ 'drivers' => [ // register `my_annotation_driver` for any entity under namespace `My\Namespace` 'My\Namespace' => 'my_annotation_driver', ], ], ], ], ];
连接设置
连接参数可以在应用程序配置中定义
<?php return [ 'doctrine' => [ 'connection' => [ // default connection name 'orm_default' => [ 'driverClass' => \Doctrine\DBAL\Driver\PDOMySql\Driver::class, 'params' => [ 'host' => 'localhost', 'port' => '3306', 'user' => 'username', 'password' => 'password', 'dbname' => 'database', ], ], ], ], ];
完整的配置选项
配置选项的详尽列表可以直接在各个模块的 Options 类中找到。
有关模块功能的文档可以在以下链接中找到
已注册服务名称
doctrine.connection.orm_default
:一个Doctrine\DBAL\Connection
实例doctrine.configuration.orm_default
:一个Doctrine\ORM\Configuration
实例doctrine.driver.orm_default
:默认映射驱动程序实例doctrine.entitymanager.orm_default
:一个Doctrine\ORM\EntityManager
实例Doctrine\ORM\EntityManager
:是doctrine.entitymanager.orm_default
的别名doctrine.eventmanager.orm_default
:一个Doctrine\Common\EventManager
实例
命令行
如下访问 Doctrine 命令行
./vendor/bin/doctrine-module
服务定位器
要访问实体管理器,请使用主服务定位器
// for example, in a controller: $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); $em = $this->getServiceLocator()->get(\Doctrine\ORM\EntityManager::class);