コード例 #1
1
    /**
     * @depends testLoadMapping
     * @param ClassMetadata $class
     */
    public function testEntityTableNameAndInheritance($class)
    {
        $this->assertEquals('cms_users', $class->getTableName());
        $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType);

        return $class;
    }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function __construct(EntityManager $em, ClassMetadata $class)
 {
     if ($class->getReflectionClass()->isSubclassOf('Gedmo\\Translatable\\Entity\\MappedSuperclass\\AbstractPersonalTranslation')) {
         throw new \Gedmo\Exception\UnexpectedValueException('This repository is useless for personal translations');
     }
     parent::__construct($em, $class);
 }
コード例 #3
0
 public function test_custom_region_gets_set_on_the_meta_data_on_build()
 {
     $cache = $this->factory('READ_ONLY', 'custom_region');
     $cache->build();
     $mapping = $this->metadata->getAssociationMapping($this->field);
     $this->assertEquals('custom_region', $mapping['cache']['region']);
 }
コード例 #4
0
 /**
  * @param Builder\Metadata $meta
  * @param \Doctrine\ORM\Mapping\ClassMetadata $cm
  */
 private function loadMeta(Builder\Metadata $meta, \Doctrine\ORM\Mapping\ClassMetadata $cm)
 {
     $type = null;
     if ($cm->hasField($meta->name)) {
         $map = $cm->getFieldMapping($meta->name);
         $type = $map['type'];
         switch ($type) {
             case 'smallint':
             case 'bigint':
                 $type = 'integer';
                 break;
             default:
                 break;
         }
         if (!isset($map['nullable']) || $map['nullable'] === false && !isset($meta->conditions['required'])) {
             $meta->conditions['required'] = true;
         }
         if (isset($map['length']) && $map['length'] && !isset($meta->conditions['maxLenght'])) {
             $meta->conditions['maxLength'] = $map['length'];
         }
         if ($type === 'decimal' && isset($map['scale'])) {
             $type = 'float';
             $meta->custom['step'] = pow(10, -$map['scale']);
         }
     } elseif ($cm->hasAssociation($meta->name)) {
         $map = $cm->getAssociationMapping($meta->name);
         $type = $map['targetEntity'];
     }
     if (!$meta->type) {
         $meta->type = $type;
     }
 }
コード例 #5
0
ファイル: MetadataBuilder.php プロジェクト: ramunasd/platform
 /**
  * @param EntityMetadata $entityMetadata
  * @param ClassMetadata $classMetadata
  */
 protected function addDoctrineAssociations(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
 {
     foreach ($classMetadata->getAssociationMappings() as $fieldName => $associationMapping) {
         $fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $associationMapping);
         $entityMetadata->addFieldMetadata($fieldMetadata);
     }
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     $className = $targetEntity->getName();
     if (isset(self::$disabled[$className])) {
         return '';
     } elseif (array_key_exists($targetEntity->rootEntityName, self::$disabled)) {
         return '';
     }
     $dataKey = $className . '|' . $targetTableAlias;
     if (!isset(self::$data[$dataKey])) {
         $annotation = $this->getReflectionService()->getClassAnnotation($className, SoftDeletable::class);
         if ($annotation !== null) {
             $existingProperties = $this->getReflectionService()->getClassPropertyNames($className);
             if (!in_array($annotation->deleteProperty, $existingProperties)) {
                 throw new PropertyNotFoundException("Property '" . $annotation->deleteProperty . "' not found for '" . $className . "'", 1439207432);
             }
             $conn = $this->getEntityManager()->getConnection();
             $platform = $conn->getDatabasePlatform();
             $column = $targetEntity->getQuotedColumnName($annotation->deleteProperty, $platform);
             $addCondSql = $platform->getIsNullExpression($targetTableAlias . '.' . $column);
             if ($annotation->timeAware) {
                 $addCondSql .= ' OR ' . $targetTableAlias . '.' . $column . ' > ' . $conn->quote(date('Y-m-d H:i:s'));
             }
             self::$data[$dataKey] = $addCondSql;
         } else {
             self::$data[$dataKey] = false;
         }
     }
     return self::$data[$dataKey] ? self::$data[$dataKey] : '';
 }
 /**
  * @expectedException Prezent\Doctrine\Translatable\Mapping\MappingException
  */
 public function testClassMetadataValidation()
 {
     $classMetadata = new ClassMetadata('Prezent\\Tests\\Fixture\\BadMappingTranslation');
     $classMetadata->initializeReflection(new RuntimeReflectionService());
     $eventArgs = new LoadClassMetadataEventArgs($classMetadata, $this->getEntityManager());
     $this->getTranslatableListener()->loadClassMetadata($eventArgs);
 }
コード例 #8
0
 function let(EntityManager $em, Connection $connection)
 {
     $classMetadata = new ClassMetadata('Acme\\Bundle\\AppBundle\\Entity\\Color');
     $classMetadata->mapField(['fieldName' => 'sortOrder', 'type' => 'integer']);
     $em->getConnection()->willReturn($connection);
     $this->beConstructedWith($em, $classMetadata);
 }
コード例 #9
0
 /**
  * Prepare stub data and mocks
  *
  * @return array
  */
 protected function prepareStubData()
 {
     // create product stubs
     $productEntities = array();
     for ($i = 1; $i <= 5; $i++) {
         $indexerItem = new Item($this->entityManager, Product::getEntityName(), $i);
         $entity = new Product($i);
         $productEntities[$i] = $entity;
         $this->productStubs[$i] = array('indexer_item' => $indexerItem, 'entity' => $entity);
     }
     $productMetadata = new ClassMetadata(Product::getEntityName());
     $productMetadata->setIdentifier(array('id'));
     $reflectionProperty = new \ReflectionProperty('Oro\\Bundle\\SearchBundle\\Tests\\Unit\\Formatter\\Stub\\Product', 'id');
     $reflectionProperty->setAccessible(true);
     $productMetadata->reflFields['id'] = $reflectionProperty;
     // create category stubs
     $categoryEntities = array();
     for ($i = 1; $i <= 3; $i++) {
         $indexerItem = new Item($this->entityManager, Category::getEntityName(), $i);
         $entity = new Category($i);
         $categoryEntities[$i] = $entity;
         $this->categoryStubs[$i] = array('indexer_item' => $indexerItem, 'entity' => $entity);
     }
     $categoryMetadata = new ClassMetadata(Category::getEntityName());
     $categoryMetadata->setIdentifier(array('id'));
     $reflectionProperty = new \ReflectionProperty('Oro\\Bundle\\SearchBundle\\Tests\\Unit\\Formatter\\Stub\\Category', 'id');
     $reflectionProperty->setAccessible(true);
     $categoryMetadata->reflFields['id'] = $reflectionProperty;
     // create metadata factory for stubs
     $this->stubMetadata = new ClassMetadataFactory($this->entityManager);
     $this->stubMetadata->setMetadataFor(Product::getEntityName(), $productMetadata);
     $this->stubMetadata->setMetadataFor(Category::getEntityName(), $categoryMetadata);
     $this->entityManager->expects($this->any())->method('getMetadataFactory')->will($this->returnValue($this->stubMetadata));
     return array(Product::getEntityName() => $productEntities, Category::getEntityName() => $categoryEntities);
 }
コード例 #10
0
ファイル: PasswordReminder.php プロジェクト: spohess/orm
 /**
  * Metadata definition for static_php metadata driver.
  * @param  ClassMetadata $metadata
  * @return void
  */
 public static function loadMetadata(ClassMetadata $metadata)
 {
     $metadata->setPrimaryTable(['name' => 'password_resets']);
     $metadata->mapField(['id' => true, 'fieldName' => 'email', 'type' => 'string']);
     $metadata->mapField(['fieldName' => 'token', 'type' => 'string']);
     $metadata->mapField(['columnName' => 'created_at', 'fieldName' => 'createdAt', 'type' => 'datetime', 'nullable' => false]);
 }
コード例 #11
0
 /**
  * @return array
  */
 protected function prepareMocks()
 {
     $configuration = new Configuration();
     $configuration->addEntityNamespace('Stub', 'Oro\\Bundle\\BatchBundle\\Tests\\Unit\\ORM\\Query\\Stub');
     $classMetadata = new ClassMetadata('Entity');
     $classMetadata->mapField(['fieldName' => 'a', 'columnName' => 'a']);
     $classMetadata->mapField(['fieldName' => 'b', 'columnName' => 'b']);
     $classMetadata->setIdentifier(['a']);
     $platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\AbstractPlatform')->setMethods([])->disableOriginalConstructor()->getMockForAbstractClass();
     $statement = $this->getMockBuilder('Doctrine\\DBAL\\Statement')->setMethods(['fetch', 'fetchColumn', 'closeCursor'])->disableOriginalConstructor()->getMock();
     $driverConnection = $this->getMockBuilder('Doctrine\\DBAL\\Driver\\Connection')->setMethods(['query'])->disableOriginalConstructor()->getMockForAbstractClass();
     $driverConnection->expects($this->any())->method('query')->will($this->returnValue($statement));
     $driver = $this->getMockBuilder('Doctrine\\DBAL\\Driver')->setMethods(['connect', 'getDatabasePlatform'])->disableOriginalConstructor()->getMockForAbstractClass();
     $driver->expects($this->any())->method('connect')->will($this->returnValue($driverConnection));
     $driver->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     $connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->setMethods(['getDatabasePlatform', 'executeQuery'])->setConstructorArgs([[], $driver])->getMock();
     $connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($platform));
     /** @var UnitOfWork $unitOfWork */
     $unitOfWork = $this->getMockBuilder('UnitOfWork')->setMethods(['getEntityPersister'])->disableOriginalConstructor()->getMock();
     $entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->setMethods(['getConfiguration', 'getClassMetadata', 'getConnection', 'getUnitOfWork'])->disableOriginalConstructor()->getMock();
     $entityManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
     $entityManager->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetadata));
     $entityManager->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $entityManager->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($unitOfWork));
     return [$entityManager, $connection, $statement];
 }
コード例 #12
0
ファイル: DoctrineListener.php プロジェクト: Maksold/platform
 /**
  * Collecting discriminator map entries from child classes for entities with inheritance not equals NONE
  *
  * @param ClassMetadata $class
  * @param EntityManager $em
  *
  * @throws MappingException
  */
 protected function processDiscriminatorValues(ClassMetadata $class, EntityManager $em)
 {
     if (!$class->isInheritanceTypeNone()) {
         if ($class->isRootEntity()) {
             $allClasses = $em->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
             $FQCN = $class->getName();
             $map = $class->discriminatorMap ?: [];
             $duplicates = [];
             foreach ($allClasses as $subClassCandidate) {
                 if (is_subclass_of($subClassCandidate, $FQCN) && !in_array($subClassCandidate, $map, true)) {
                     $value = $this->getDiscriminatorValue($em->getMetadataFactory(), $subClassCandidate);
                     if (null !== $value) {
                         if (isset($map[$value])) {
                             $duplicates[] = $value;
                         }
                         $map[$value] = $subClassCandidate;
                     }
                 }
             }
             if ($duplicates) {
                 throw MappingException::duplicateDiscriminatorEntry($class->getName(), $duplicates, $map);
             }
             $class->setDiscriminatorMap($map);
             $this->collectedMaps = array_merge($this->collectedMaps, array_fill_keys(array_values($map), $map));
         } elseif (isset($this->collectedMaps[$class->name]) && $class->discriminatorMap !== $this->collectedMaps[$class->name]) {
             $class->setDiscriminatorMap($this->collectedMaps[$class->name]);
         }
     }
 }
コード例 #13
0
 /**
  * @param $action
  * @param \Doctrine\ORM\Mapping\ClassMetadata $meta
  * @param $entity
  */
 private function logEntityChange($action, \Doctrine\ORM\Mapping\ClassMetadata $meta, $entity)
 {
     $userToken = $this->container->get('security.context')->getToken();
     if (null !== $userToken) {
         $this->logger->info('Entity "' . $meta->getTableName() . '" with id: ' . $meta->getFieldValue($entity, $meta->getSingleIdentifierFieldName()) . ' ' . $action . ' by: ' . $this->container->get('security.context')->getToken()->getUsername());
     }
 }
コード例 #14
0
 protected function updateTranslationMetadata(ClassMetadata $metadata)
 {
     if (!$metadata->hasAssociation('translatable')) {
         $metadata->mapManyToOne(['fieldName' => 'translatable', 'inversedBy' => 'translations', 'fetch' => $this->translationFetchMode, 'joinColumns' => [['name' => 'translatable_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE']], 'targetEntity' => substr($metadata->name, 0, -strlen('Translation'))]);
         $metadata->table['uniqueConstraints'][] = ['name' => 'unique_translation', 'columns' => ['translatable_id', 'locale']];
     }
 }
コード例 #15
0
 public function generate($jsonSchema)
 {
     $schema = json_decode($jsonSchema, true);
     if (!isset($schema['type']) && $schema['type'] !== 'object') {
         throw new \RuntimeException("Unable to process the schema");
     }
     if (!isset($schema['title'])) {
         throw new \RuntimeException("title property must be defined");
     }
     // TODO investigate implementation via ClassMetadataBuilder
     $className = $schema['title'];
     $medatadata = new ClassMetadata($this->getNamespace() . '\\' . $className);
     if (isset($schema['properties'])) {
         foreach ($schema['properties'] as $name => $definition) {
             $type = $definition['type'];
             $nullable = isset($schema['required']) ? !in_array($name, $schema['required']) : true;
             $medatadata->mapField(['fieldName' => $name, 'type' => $type, 'nullable' => $nullable, 'options' => []]);
         }
     }
     $filename = sprintf("%s/%s/%s.php", $this->getPath(), join('/', explode('\\', $this->getNamespace())), $className);
     mkdir(dirname($filename), 0777, true);
     $generator = new EntityGenerator();
     $generator->setGenerateAnnotations(true);
     file_put_contents($filename, $generator->generateEntityClass($medatadata));
 }
コード例 #16
0
ファイル: ProxyFactoryTest.php プロジェクト: pnaq57/zf2demo
 /**
  * @group DDC-1771
  */
 public function testSkipAbstractClassesOnGeneration()
 {
     $cm = new ClassMetadata(__NAMESPACE__ . '\\AbstractClass');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $this->assertNotNull($cm->reflClass);
     $num = $this->proxyFactory->generateProxyClasses(array($cm));
     $this->assertEquals(0, $num, "No proxies generated.");
 }
コード例 #17
0
 /**
  * @group DDC-268
  */
 public function testColumnWithMissingTypeDefaultsToString()
 {
     $cm = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\ColumnWithoutType');
     $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $annotationDriver = $this->_loadDriver();
     $annotationDriver->loadMetadataForClass('Doctrine\\Tests\\ORM\\Mapping\\InvalidColumn', $cm);
     $this->assertEquals('string', $cm->fieldMappings['id']['type']);
 }
コード例 #18
0
 public function getResult(ClassMetadata $classMetadata, array $options = [])
 {
     $annotation = $this->reader->getClassAnnotation($classMetadata->getReflectionClass(), $this->annotationClass);
     if (is_a($annotation, $this->annotationClass)) {
         return $annotation;
     }
     return $this->getFallbackResult($classMetadata, $options);
 }
コード例 #19
0
 function it_processes_the_lcm_event(LoadClassMetadataEventArgs $eventArgs, ClassMetadata $classMetadata)
 {
     $this->beConstructedWith('Your\\Custom\\Entity');
     $classMetadata->getName()->willReturn(UserPermission::class);
     $classMetadata->getName()->shouldBeCalled();
     $eventArgs->getClassMetadata()->willReturn($classMetadata);
     $this->loadClassMetadata($eventArgs);
 }
コード例 #20
0
 /**
  * Gets the SQL query part to add to a query.
  *
  * @param ClassMetaData $targetEntity
  * @param string $targetTableAlias
  *
  * @return string The constraint SQL if there is available, empty string otherwise.
  */
 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     if ($targetEntity->hasField('deletedAt')) {
         $now = date('Y-m-d H:i:s');
         return "{$targetTableAlias}.deletedAt IS NULL OR {$targetTableAlias}.deletedAt > '{$now}'";
     }
     return '';
 }
コード例 #21
0
ファイル: FieldProvider.php プロジェクト: xamin123/platform
 /**
  * {@inheritdoc}
  */
 protected function isIgnoredRelation(ClassMetadata $metadata, $associationName)
 {
     // skip workflow and collection relations
     if ($this->isWorkflowField($associationName) || !$metadata->isSingleValuedAssociation($associationName)) {
         return true;
     }
     return parent::isIgnoredRelation($metadata, $associationName);
 }
コード例 #22
0
ファイル: CmsNodeQuery.php プロジェクト: mikegibson/sentient
 /**
  * @param ClassMetadata $classMetadata
  * @return \Doctrine\Common\Persistence\ObjectRepository
  */
 protected function getRepository(ClassMetadata $classMetadata)
 {
     $repository = $this->managerRegistry->getRepository($classMetadata->getName());
     if (!$repository instanceof ManagedRepositoryInterface) {
         return false;
     }
     return $repository;
 }
コード例 #23
0
ファイル: Listener.php プロジェクト: norbe/framework
	/**
	 * Update the discriminator map
	 * @param \Doctrine\ORM\Mapping\ClassMetadata $metadata
	 * @param \Doctrine\ORM\EntityManager $em
	 */
	private function updateDiscriminator(\Doctrine\ORM\Mapping\ClassMetadata $metadata, \Doctrine\ORM\EntityManager $em)
	{
    	if ($metadata->name == 'Nella\Media\FileEntity' || in_array('Nella\Media\FileEntity', $metadata->parentClasses)) {
			$metadata->setDiscriminatorMap(array_merge($metadata->discriminatorMap, $this->fileMap));
    	} elseif ($metadata->name == 'Nella\Media\ImageEntity' || in_array('Nella\Media\ImageEntity', $metadata->parentClasses)) {
			$metadata->setDiscriminatorMap(array_merge($metadata->discriminatorMap, $this->imageMap));
    	}
	}
コード例 #24
0
 /**
  * {@inheritdoc}
  */
 public function isIgnoredRelation(ClassMetadata $metadata, $associationName)
 {
     $mapping = $metadata->getAssociationMapping($associationName);
     if (!$mapping['isOwningSide'] || !($mapping['type'] & ClassMetadata::TO_ONE)) {
         return false;
     }
     return $associationName === 'workflowItem' || $associationName === 'workflowStep';
 }
コード例 #25
0
 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     if ($targetEntity->hasField('del_flg') && !in_array($targetEntity->getName(), $this->getExcludes())) {
         return $targetTableAlias . '.del_flg = 0';
     } else {
         return "";
     }
 }
コード例 #26
0
 /**
  * @param ClassMetadata $meteData
  * @return string
  */
 public function getNameLabelField(ClassMetadata $meteData)
 {
     $fieldNames = $meteData->getFieldNames();
     if (in_array('label', $fieldNames)) {
         return 'label';
     }
     return 'name';
 }
コード例 #27
0
 /**
  * {@inheritdoc}
  */
 public function getResult(ClassMetadata $classMetadata, array $options = [])
 {
     $cmsEntity = $this->reader->getClassAnnotation($classMetadata->getReflectionClass(), 'Sentient\\Cms\\Data\\Metadata\\Annotation\\CmsEntity');
     if (!empty($cmsEntity->slug)) {
         return $cmsEntity->slug;
     }
     return $this->entityNameQuery->getResult($classMetadata);
 }
 /**
  * {@inheritdoc}
  */
 protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r')
 {
     $columnName = $class->columnNames[$field];
     $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $class->getQuotedColumnName($field, $this->_platform);
     $columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++);
     $this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name);
     return $sql . ' AS ' . $columnAlias;
 }
 protected function setUp()
 {
     $this->meta = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->setMethods(['getName'])->getMock();
     $this->meta->expects($this->any())->method('getName')->will($this->returnValue('SR\\Doctrine\\ORM\\Id\\StringUuid4Generator'));
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->setMethods(['getClassMetadata', 'find'])->getMock();
     $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($this->meta));
     $this->em->expects($this->any())->method('find')->will($this->returnValue(null));
     $this->entity = $this->getMockBuilder('SR\\Doctrine\\ORM\\Mapping\\Entity')->getMock();
 }
コード例 #30
0
 public static function getValueFieldFallback(ClassMetadata $classMetadata)
 {
     foreach (self::$valueFieldsFallback as $field) {
         if ($classMetadata->hasField($field)) {
             return $field;
         }
     }
     return NULL;
 }