當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Mapping\ClassMetadata類代碼示例

本文整理匯總了PHP中Doctrine\ORM\Mapping\ClassMetadata的典型用法代碼示例。如果您正苦於以下問題:PHP ClassMetadata類的具體用法?PHP ClassMetadata怎麽用?PHP ClassMetadata使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ClassMetadata類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testEntityTableNameAndInheritance

    /**
     * @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;
    }
開發者ID:naderman,項目名稱:doctrine2,代碼行數:11,代碼來源:AbstractMappingDriverTest.php

示例2: __construct

 /**
  * {@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);
 }
開發者ID:n1c01a5,項目名稱:DoctrineExtensions,代碼行數:10,代碼來源:TranslationRepository.php

示例3: loadMeta

 /**
  * @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;
     }
 }
開發者ID:voda,項目名稱:formbuilder,代碼行數:36,代碼來源:DoctrineAnnotationLoader.php

示例4: addDoctrineAssociations

 /**
  * @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);
     }
 }
開發者ID:ramunasd,項目名稱:platform,代碼行數:11,代碼來源:MetadataBuilder.php

示例5: addFilterConstraint

 /**
  * {@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] : '';
 }
開發者ID:sixty-nine,項目名稱:CDSRC.Libraries,代碼行數:33,代碼來源:MarkedAsDeletedFilter.php

示例6: testClassMetadataValidation

 /**
  * @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);
 }
開發者ID:prezent,項目名稱:doctrine-translatable,代碼行數:10,代碼來源:TranslatableListenerValidationTest.php

示例7: let

 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);
 }
開發者ID:alexisfroger,項目名稱:pim-community-dev,代碼行數:7,代碼來源:ReferenceDataRepositorySpec.php

示例8: prepareStubData

 /**
  * 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);
 }
開發者ID:xamin123,項目名稱:platform,代碼行數:40,代碼來源:ResultFormatterTest.php

示例9: loadMetadata

 /**
  * 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]);
 }
開發者ID:spohess,項目名稱:orm,代碼行數:12,代碼來源:PasswordReminder.php

示例10: prepareMocks

 /**
  * @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];
 }
開發者ID:northdakota,項目名稱:platform,代碼行數:29,代碼來源:QueryCountCalculatorTest.php

示例11: processDiscriminatorValues

 /**
  * 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]);
         }
     }
 }
開發者ID:Maksold,項目名稱:platform,代碼行數:37,代碼來源:DoctrineListener.php

示例12: logEntityChange

 /**
  * @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());
     }
 }
開發者ID:binaryfr3ak,項目名稱:sfitixi,代碼行數:12,代碼來源:EntityChangeListener.php

示例13: updateTranslationMetadata

 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']];
     }
 }
開發者ID:nkt,項目名稱:translate-bundle,代碼行數:7,代碼來源:SchemaEventSubscriber.php

示例14: generate

 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));
 }
開發者ID:jeremygiberson,項目名稱:js2doctrine,代碼行數:25,代碼來源:ModelGenerator.php

示例15: testSkipAbstractClassesOnGeneration

 /**
  * @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.");
 }
開發者ID:pnaq57,項目名稱:zf2demo,代碼行數:11,代碼來源:ProxyFactoryTest.php


注:本文中的Doctrine\ORM\Mapping\ClassMetadata類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。