fabiang / doctrine-dynamic
Load Doctrine mappings dynamically for your entities by configuration
Installs: 1 042
Dependents: 2
Suggesters: 0
Security: 0
Stars: 7
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.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.6.21
- symfony/cache: ^5.4 || ^6.0
- vimeo/psalm: >=4.23
- webmozart/assert: >=1.11.0
This package is auto-updated.
Last update: 2024-11-26 12:03:59 UTC
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.