fabiang / doctrine-dynamic
通过配置动态加载实体映射
v2.0.0
2022-05-13 11:10 UTC
Requires
- php: ^7.4 || ~8.0.0 || ~8.1.0
- doctrine/common: ^3.0
- doctrine/orm: ^2.5
- doctrine/persistence: ^3.0
- laminas/laminas-hydrator: ^3.0 || ^4.0
- laminas/laminas-stdlib: ^3.0
Requires (Dev)
- behat/behat: ^3.8
- dms/phpunit-arraysubset-asserts: ^0.4.0
- doctrine/annotations: ^1.13
- laminas/laminas-coding-standard: ^2.3
- phpspec/prophecy-phpunit: ^2.0
- phpunit/php-invoker: ^3.1
- phpunit/phpunit: ^9.5
- symfony/cache: ^5.4 || ^6.0
- vimeo/psalm: ^4.23
README
Doctrine 的代理驱动,允许您通过配置动态地添加自定义关系。
如果您使用的是无法更改的外部实体,但又想在它们之间以及与您的实体之间添加自己的关系,这将非常有用。
功能
- 为实体设置所有可能的关联
- 一对一
- 多对一
- 一对多
- 多对多
- 设置仓库类
安装
初识 Composer?请阅读介绍。运行以下 Composer 命令
$ composer require fabiang/doctrine-dynamic
框架集成
使用方法
<?php use Fabiang\DoctrineDynamic\ConfigurationFactory; use Fabiang\DoctrineDynamic\ProxyDriverFactory; use Doctrine\ORM\EntityManager; $configurationFactory = new ConfigurationFactory(); $configuration = $configurationFactory->factory([ \Mymodule\Entity\Customer::class => [ 'options' => [ 'repository' => \Mymodule\Repository\CustomerRepository::class, ], 'fields' => [ 'fieldname' => [ 'products' => [ 'oneToMany' => [ [ 'targetEntity' => \Mymodule\Entity\Customer::class, 'mappedBy' => 'customer', ], ] ], ] ] ], \Mymodule\Entity\Products::class => [ 'fields' => [ 'customer' => [ 'manyToOne' => [ [ 'targetEntity' => \Mymodule\Entity\Products::class, 'inversedBy' => 'products', 'joinColumns' => [ 'name' => 'customer_id', 'referencedColumnName' => 'id' ] ], ] ], ] ], ]); /** @var $entityManager EntityManager */ // get it from a container for example $entityManager = $container->get(EntityManager::class); $proxyDriverFactory = new ProxyDriverFactory(); $proxyDriverFactory->factory($entityManager, $configuration);
开发
在 Github 上fork 项目,并提交包含您更改的 pull request。确保您在运行以下命令后没有破坏任何内容
composer install ./vendor/bin/phpunit ./vendor/bin/behat
许可
BSD-2-Clause 许可。请参阅LICENSE.md。