/**
  * @param LoadClassMetadataEventArgs $args
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $evm = $args->getEntityManager()->getEventManager();
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\CoreBundle\\Model\\TemplateInterface", "Bigfish\\Bundle\\CoreBundle\\Entity\\Template", array());
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\CoreBundle\\Model\\RouteInterface", "Bigfish\\Bundle\\CoreBundle\\Entity\\Route", array());
     $evm->addEventListener(Events::loadClassMetadata, $this->resolveTargetEntities);
 }
Exemple #2
0
 protected static function setUpEntityManager()
 {
     $config = new Configuration();
     $config->setSQLLogger(null);
     $config->setAutoGenerateProxyClasses(true);
     $config->setProxyDir(\sys_get_temp_dir());
     $config->setProxyNamespace('Proxies');
     $config->setMetadataDriverImpl(static::getMetadataDriverImpl());
     $config->setQueryCacheImpl(new ArrayCache());
     $config->setMetadataCacheImpl(new ArrayCache());
     $dbPath = __DIR__ . '/../db.sqlite';
     if (file_exists($dbPath)) {
         unlink($dbPath);
     }
     $connection = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
     // Event listeners
     $interfaces = DoctrineBundleMapping::getDefaultImplementations();
     $evm = new EventManager();
     // Resolve entity target subscriber
     $rtel = new ResolveTargetEntityListener();
     foreach ($interfaces as $model => $implementation) {
         $rtel->addResolveTargetEntity($model, $implementation, []);
     }
     $evm->addEventSubscriber($rtel);
     // Load metadata subscriber
     $lm = new LoadMetadataSubscriber([], $interfaces);
     $evm->addEventSubscriber($lm);
     static::$em = EntityManager::create($connection, $config, $evm);
 }
 /**
  * @param LoadClassMetadataEventArgs $args
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $evm = $args->getEntityManager()->getEventManager();
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\EavBundle\\Model\\ModuleInterface", "Bigfish\\Bundle\\EavBundle\\Entity\\Module", array());
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\EavBundle\\Model\\ContainerInterface", "Bigfish\\Bundle\\EavBundle\\Entity\\Container", array());
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\EavBundle\\Model\\FieldInterface", "Bigfish\\Bundle\\EavBundle\\Entity\\Field", array());
     $evm->addEventListener(Events::loadClassMetadata, $this->resolveTargetEntities);
 }
 /**
  * @group DDC-2109
  */
 public function testAssertTableColumnsAreNotAddedInManyToMany()
 {
     $evm = $this->em->getEventManager();
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', array());
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\TargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\TargetEntity', array());
     $evm->addEventListener(Events::loadClassMetadata, $this->listener);
     $cm = $this->factory->getMetadataFor('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity');
     $meta = $cm->associationMappings['manyToMany'];
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\TargetEntity', $meta['targetEntity']);
     $this->assertEquals(array('resolvetargetentity_id', 'targetinterface_id'), $meta['joinTableColumns']);
 }
 /**
  * @return EntityManager
  */
 private static function createEntityManager()
 {
     $config = \Doctrine\ORM\Tools\Setup::createConfiguration(true);
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([__DIR__ . '/../../../../src/Driver/Doctrine/ORM/Entity', __DIR__ . '/Entity'], false));
     $rtel = new ResolveTargetEntityListener();
     $rtel->addResolveTargetEntity('FOS\\Message\\Model\\PersonInterface', 'FOS\\Message\\Tests\\Driver\\Doctrine\\ORM\\Entity\\TestPerson', []);
     $evm = new EventManager();
     $evm->addEventListener(Events::loadClassMetadata, $rtel);
     $dbParams = ['driver' => 'pdo_sqlite', 'path' => self::$dbFile];
     return \Doctrine\ORM\EntityManager::create($dbParams, $config, $evm);
 }
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $options \DoctrineORMModule\Options\EntityResolver */
     $options = $this->getOptions($serviceLocator, 'entity_resolver');
     $eventManager = $serviceLocator->get($options->getEventManager());
     $resolvers = $options->getResolvers();
     $targetEntityListener = new ResolveTargetEntityListener();
     foreach ($resolvers as $oldEntity => $newEntity) {
         $targetEntityListener->addResolveTargetEntity($oldEntity, $newEntity, array());
     }
     $eventManager->addEventListener(Events::loadClassMetadata, $targetEntityListener);
     return $eventManager;
 }
 /**
  * @group DDC-1544
  */
 public function testResolveTargetEntityListenerCanResolveTargetEntity()
 {
     $evm = $this->em->getEventManager();
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', array());
     $this->listener->addResolveTargetEntity('Doctrine\\Tests\\ORM\\Tools\\TargetInterface', 'Doctrine\\Tests\\ORM\\Tools\\TargetEntity', array());
     $evm->addEventListener(Events::loadClassMetadata, $this->listener);
     $cm = $this->factory->getMetadataFor('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity');
     $meta = $cm->associationMappings;
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\TargetEntity', $meta['manyToMany']['targetEntity']);
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', $meta['manyToOne']['targetEntity']);
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\ResolveTargetEntity', $meta['oneToMany']['targetEntity']);
     $this->assertSame('Doctrine\\Tests\\ORM\\Tools\\TargetEntity', $meta['oneToOne']['targetEntity']);
 }
Exemple #8
0
 public function setUpEntityManager(EntityManager $entityManager, callable $aclLocator)
 {
     if ($this->securityIdentityClass === null) {
         throw new \RuntimeException('The security identity class must be configured: call ->setSecurityIdentityClass("...")');
     }
     $evm = $entityManager->getEventManager();
     // Configure which entity implements the SecurityIdentityInterface
     $rtel = new ResolveTargetEntityListener();
     $rtel->addResolveTargetEntity('MyCLabs\\ACL\\Model\\SecurityIdentityInterface', $this->securityIdentityClass, []);
     $evm->addEventListener(Events::loadClassMetadata, $rtel);
     // Register the metadata loader
     $evm->addEventListener(Events::loadClassMetadata, $this->metadataLoader);
     // Register the listener that looks for new resources
     $evm->addEventSubscriber(new EntityResourcesListener($aclLocator));
 }
Exemple #9
0
 public function testResolveTargetEntitiesChangesDiscriminatorMapValues()
 {
     $resolveTargetEntity = new ResolveTargetEntityListener();
     $resolveTargetEntity->addResolveTargetEntity(DDC3300BossInterface::INTERFACENAME, DDC3300Boss::CLASSNAME, array());
     $resolveTargetEntity->addResolveTargetEntity(DDC3300EmployeeInterface::INTERFACENAME, DDC3300Employee::CLASSNAME, array());
     $this->_em->getEventManager()->addEventSubscriber($resolveTargetEntity);
     $this->_schemaTool->createSchema(array($this->_em->getClassMetadata(DDC3300Person::CLASSNAME)));
     $boss = new DDC3300Boss();
     $employee = new DDC3300Employee();
     $this->_em->persist($boss);
     $this->_em->persist($employee);
     $this->_em->flush();
     $this->_em->clear();
     $this->assertEquals($boss, $this->_em->find(DDC3300BossInterface::INTERFACENAME, $boss->id));
     $this->assertEquals($employee, $this->_em->find(DDC3300EmployeeInterface::INTERFACENAME, $employee->id));
 }
 /**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     /* @var $options \DoctrineORMModule\Options\EntityResolver */
     $options = $this->getOptions($serviceLocator, 'entity_resolver');
     $eventManager = $serviceLocator->get($options->getEventManager());
     $resolvers = $options->getResolvers();
     $targetEntityListener = new ResolveTargetEntityListener();
     foreach ($resolvers as $oldEntity => $newEntity) {
         $targetEntityListener->addResolveTargetEntity($oldEntity, $newEntity, array());
     }
     // Starting from Doctrine ORM 2.5, the listener implements EventSubscriber
     if ($targetEntityListener instanceof EventSubscriber) {
         $eventManager->addEventSubscriber($targetEntityListener);
     } else {
         $eventManager->addEventListener(Events::loadClassMetadata, $targetEntityListener);
     }
     return $eventManager;
 }
 /**
  * {@inheritdoc}
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $event)
 {
     $map = [];
     $metadata = $event->getClassMetadata();
     foreach ($metadata->discriminatorMap as $discriminatorName => $discriminatorClass) {
         if (isset($this->resolveTargetEntities[$discriminatorClass])) {
             $map[$discriminatorName] = $this->resolveTargetEntities[$discriminatorClass]['targetEntity'];
         }
     }
     $metadata->setDiscriminatorMap($map);
     parent::loadClassMetadata($event);
 }
 /**
  * @param LoadClassMetadataEventArgs $args
  */
 public function loadClassMetadata(LoadClassMetadataEventArgs $args)
 {
     $evm = $args->getEntityManager()->getEventManager();
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\MediaBundle\\Model\\AttachmentInterface", "Bigfish\\Bundle\\MediaBundle\\Entity\\Attachment", array());
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\MediaBundle\\Model\\CategoryInterface", "Bigfish\\Bundle\\MediaBundle\\Entity\\Category", array());
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\MediaBundle\\Model\\AttachmentImageCroppingInterface", "Bigfish\\Bundle\\MediaBundle\\Entity\\ImageCropping", array());
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\MediaBundle\\Model\\ImageDimensionInterface", "Bigfish\\Bundle\\MediaBundle\\Entity\\ImageDimension", array());
     $this->resolveTargetEntities->addResolveTargetEntity("Bigfish\\Bundle\\MediaBundle\\Model\\ImageInstanceInterface", "Bigfish\\Bundle\\MediaBundle\\Entity\\ImageInstance", array());
     $evm->addEventListener(Events::loadClassMetadata, $this->resolveTargetEntities);
 }
 private function loadEventManager(ContainerBuilder $container, $config)
 {
     $definition = new Definition('Doctrine\\Common\\EventManager');
     foreach ($config['listeners'] as $listener) {
         $definition->addMethodCall('addEventSubscriber', array($listener));
     }
     $listener = new ResolveTargetEntityListener();
     foreach ($config['targets'] as $source => $target) {
         $listener->addResolveTargetEntity($source, $target, array());
     }
     $definition->addMethodCall('addEventListener', array(Events::loadClassMetadata, $listener));
     $container->setDefinition('doctrine.event_manager', $definition);
 }