/**
  * Test setup
  */
 protected function setUp()
 {
     // setup entity aliases
     $this->em = DoctrineTestHelper::createTestEntityManager();
     $entityManagerNamespaces = $this->em->getConfiguration()->getEntityNamespaces();
     $entityManagerNamespaces['WebtownPhpBannerBundle'] = 'WebtownPhp\\BannerBundle\\Entity';
     $this->em->getConfiguration()->setEntityNamespaces($entityManagerNamespaces);
     // setup schema
     $schemaTool = new SchemaTool($this->em);
     $classes = [];
     foreach ($this->getEntities() as $entityClass) {
         $classes[] = $this->em->getClassMetadata($entityClass);
     }
     try {
         $schemaTool->dropSchema($classes);
     } catch (\Exception $e) {
     }
     try {
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     $registry = \Mockery::mock('Doctrine\\Bundle\\DoctrineBundle\\Registry');
     $registry->shouldReceive('getManager')->andReturn($this->em);
     $this->bm = new ORMManager($registry, new EventDispatcher());
 }
 /**
  * Initializes extension driver
  *
  * @param ObjectManager $objectManager
  * @param string $extensionNamespace
  * @param object $annotationReader
  */
 public function __construct(ObjectManager $objectManager, $extensionNamespace, $annotationReader)
 {
     $this->objectManager = $objectManager;
     $this->annotationReader = $annotationReader;
     $this->extensionNamespace = $extensionNamespace;
     $omDriver = $objectManager->getConfiguration()->getMetadataDriverImpl();
     $this->driver = $this->getDriver($omDriver);
 }
 /**
  * @param string $class
  * @param ObjectManager $om
  * @return array
  */
 private function getSubClasses($class, ObjectManager $om)
 {
     $classes = [];
     foreach ($om->getConfiguration()->getMetadataDriverImpl()->getAllClassNames() as $className) {
         if (is_subclass_of($className, $class, true)) {
             $classes[] = $className;
         }
     }
     return $classes;
 }
 /**
  * Returns information about which entities exist and possibly if their
  * mapping information contains errors or not.
  *
  * @return array
  */
 public function getEntityStatus()
 {
     $entityClassNames = $this->entityManager->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
     $info = array();
     foreach ($entityClassNames as $entityClassName) {
         try {
             $info[$entityClassName] = $this->entityManager->getClassMetadata($entityClassName);
         } catch (\Doctrine\ORM\Mapping\MappingException $e) {
             $info[$entityClassName] = $e->getMessage();
         }
     }
     return $info;
 }
 /**
  * Initializes extension driver.
  *
  * @param \Doctrine\Common\Persistence\ObjectManager $objectManager
  * @param string $extensionNamespace
  * @param object $annotationReader
  */
 public function __construct(ObjectManager $objectManager, $extensionNamespace, $annotationReader)
 {
     $this->objectManager = $objectManager;
     $this->annotationReader = $annotationReader;
     $this->extensionNamespace = $extensionNamespace;
     $omDriver = $objectManager->getConfiguration()->getMetadataDriverImpl();
     $omCache = $this->objectManager->getMetadataFactory()->getCacheDriver();
     $metadataClassName = null;
     if (class_exists($this->extensionNamespace . '\\Mapping\\ClassMetadata')) {
         $metadataClassName = $this->extensionNamespace . '\\Mapping\\ClassMetadata';
     }
     $driver = $this->getDriver($omDriver);
     $driver->setBaseMetadataFactory($objectManager->getMetadataFactory());
     parent::__construct($driver, $omCache, $extensionNamespace, $metadataClassName);
 }
 /**
  * @param DoctrineSqlFilter $sqlFilter
  * @param ClassMetadata $targetEntity
  * @param string $targetTableAlias
  * @return string
  * @throws InvalidQueryRewritingConstraintException
  * @throws \Exception
  */
 public function getSql(DoctrineSqlFilter $sqlFilter, ClassMetadata $targetEntity, $targetTableAlias)
 {
     $targetEntityPropertyName = strpos($this->path, '.') ? substr($this->path, 0, strpos($this->path, '.')) : $this->path;
     $quoteStrategy = $this->entityManager->getConfiguration()->getQuoteStrategy();
     if ($targetEntity->hasAssociation($targetEntityPropertyName) === FALSE) {
         return $this->getSqlForSimpleProperty($sqlFilter, $quoteStrategy, $targetEntity, $targetTableAlias, $targetEntityPropertyName);
     } elseif (strstr($this->path, '.') === FALSE && $targetEntity->isSingleValuedAssociation($targetEntityPropertyName) === TRUE && $targetEntity->isAssociationInverseSide($targetEntityPropertyName) === FALSE) {
         return $this->getSqlForManyToOneAndOneToOneRelationsWithoutPropertyPath($sqlFilter, $quoteStrategy, $targetEntity, $targetTableAlias, $targetEntityPropertyName);
     } elseif ($targetEntity->isSingleValuedAssociation($targetEntityPropertyName) === TRUE && $targetEntity->isAssociationInverseSide($targetEntityPropertyName) === FALSE) {
         return $this->getSqlForManyToOneAndOneToOneRelationsWithPropertyPath($sqlFilter, $quoteStrategy, $targetEntity, $targetTableAlias, $targetEntityPropertyName);
     } elseif ($targetEntity->isSingleValuedAssociation($targetEntityPropertyName) === TRUE && $targetEntity->isAssociationInverseSide($targetEntityPropertyName) === TRUE) {
         throw new InvalidQueryRewritingConstraintException('Single valued properties from the inverse side are not supported in a content security constraint path! Got: "' . $this->path . ' ' . $this->operator . ' ' . $this->operandDefinition . '"', 1416397754);
     } elseif ($targetEntity->isCollectionValuedAssociation($targetEntityPropertyName) === TRUE) {
         throw new InvalidQueryRewritingConstraintException('Multivalued properties are not supported in a content security constraint path! Got: "' . $this->path . ' ' . $this->operator . ' ' . $this->operandDefinition . '"', 1416397655);
     }
     throw new InvalidQueryRewritingConstraintException('The configured operator of the entity constraint is not valid/supported. Got: ' . $this->operator, 1270483540);
 }
Beispiel #7
0
 /**
  * Create a driver from a Doctrine object manager.
  *
  * @param ObjectManager $om
  *
  * @return DriverInterface
  */
 public static function driversFromManager(ObjectManager $om)
 {
     return self::driversFromMetadataDriver($om->getConfiguration()->getMetadataDriverImpl());
 }