fabiang / doctrine-dynamic
Load Doctrine mappings dynamically for your entities by configuration
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
Proxy Driver for Doctrine which allows you to add custom relations dynamically by configuration.
This is useful if you use foreign entities, which you can't change, but you like to add own relations between them and your entities.
Features
- Setting all possible relations to entities:
- OneToOne
- ManyToOne
- OneToMany
- ManyToMany
- Setting repository class
Installation
New to Composer? Read the introduction. Run the following Composer command:
$ composer require fabiang/doctrine-dynamic
Framework integration
Usage
<?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);
Development
This library is tested with PHPUnit and Behat.
Fork the project on Github and send an pull request with your changes. Make sure you didn't break anything with running the following commands:
composer install ./vendor/bin/phpunit ./vendor/bin/behat
Licence
BSD-2-Clause. See the LICENSE.md.