mapado / doctrine-blender
Package in charge of "blending" doctrine entities (ORM, ODM, etc.)
Installs: 6 227
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 14
Forks: 0
Open Issues: 0
Requires
- doctrine/common: 2.*
Requires (Dev)
- phpunit/phpunit: 4.2.*
Suggests
- doctrine/mongodb-odm: 1.*
- doctrine/orm: 2.*
- mapado/elastica-query-bundle: 1.*
- symfony/yaml: 2.*
README
This package makes it really simple to "blend" doctrine entities (ORM, ODM, etc.).
It is greatly inspired by the Doctrine MongoDB ODM documentation on the subject.
Current status
It should work with every doctrine package. It is tested with Doctrine ORM and Doctrine MongoDB.
It also working with mapado/elastica-query-bundle in the ElasticSearch => Doctrine direction.
Installation
composer require "mapado/doctrine-blender:0.*"
Usage
Mixing ORM Entity and ODM Document
use Mapado\DoctrineBlender\ObjectBlender; use Mapado\DoctrineBlender\ExternalAssociation; $documentManager = ... // get a document manager $entityManager = ... // get an entity manager $eventSubscriber = new ObjectBlender; $eventSubscriber->mapExternalAssociation( new ExternalAssociation( $entityManager, 'Acme\Entity\Order', 'product', $documentManager, 'Acme\Document\Product', 'getProductId', // optional, auto-generated with the property name 'setProduct' // optional, auto-generated with the property name ) );
Mixing ORM Entities living in different Entity Manager
It is really easy to mix ORM Entities as well:
use Mapado\DoctrineBlender\ObjectBlender; use Mapado\DoctrineBlender\ExternalAssociation; $entityManager = ... // get an entity manager $secondEntityManager = ... // get the second manager $eventSubscriber = new ObjectBlender; $eventSubscriber->mapExternalAssociation( new ExternalAssociation( $entityManager, 'Acme\Entity\Order', 'product', $secondEntityManager, 'Acme\Document\Product' ) );
Configuration
Yaml
doctrine_external_association: client_address: # this key is only for you source_object_manager_alias: product_em # an alias you will need to inject later classname: 'Entity\Product' property_name: 'product' reference_object_manager_alias: order_dm # another alia reference_class: 'Document\Order' reference_getter: 'getProductId' reference_setter: 'setProduct'
use Mapado\DoctrineBlender\Configuration\YamlConfiguration; $ymlConf = new YamlConfiguration('/path/to/external_association.yml'); $entityManager = ... // get an entity manager $documentManager = ... // get a document manager $ymlConf->setObjectManagerReference('product_em', $entityManager) ->setObjectManagerReference('order_dm', $documentManager) ;