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


PHP Mapping\ClassMetadataFactory類代碼示例

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


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

示例1: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockDriver = new MetadataDriverMock();
     $entityManager = $this->_createEntityManager($mockDriver);
     $conn = $entityManager->getConnection();
     $mockPlatform = $conn->getDatabasePlatform();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     $cm1 = $this->_createValidClassMetadata();
     // SUT
     $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $cmf->setEntityManager($entityManager);
     $cmf->setMetadataFor($cm1->name, $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(2, count($cm1->associationMappings));
     $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
     $this->assertEquals('group', $cm1->table['name']);
     // Go
     $cmMap1 = $cmf->getMetadataFor($cm1->name);
     $this->assertSame($cm1, $cmMap1);
     $this->assertEquals('group', $cmMap1->table['name']);
     $this->assertTrue($cmMap1->table['quoted']);
     $this->assertEquals(array(), $cmMap1->parentClasses);
     $this->assertTrue($cmMap1->hasField('name'));
 }
開發者ID:naumangcu,項目名稱:doctrine2,代碼行數:28,代碼來源:ClassMetadataFactoryTest.php

示例2: testEmbeddedMappingsWithFalseUseColumnPrefix

 /**
  * @group DDC-3293
  * @group DDC-3477
  * @group 1238
  */
 public function testEmbeddedMappingsWithFalseUseColumnPrefix()
 {
     $factory = new ClassMetadataFactory();
     $em = $this->_getTestEntityManager();
     $em->getConfiguration()->setMetadataDriverImpl($this->_loadDriver());
     $factory->setEntityManager($em);
     $this->assertFalse($factory->getMetadataFor('Doctrine\\Tests\\Models\\DDC3293\\DDC3293User')->embeddedClasses['address']['columnPrefix']);
 }
開發者ID:selimcr,項目名稱:servigases,代碼行數:13,代碼來源:XmlMappingDriverTest.php

示例3: setUp

 public function setUp()
 {
     $this->metadataFactory = $this->getMock(ClassMetadataFactory::class);
     $this->metadataFactory->method('hasMetadataFor')->will($this->returnValueMap([[DummyEntity::class, true], [DummyEmbeddable::class, true]]));
     $this->metadataFactory->method('getMetadataFor')->will($this->returnValueMap([[DummyEntity::class, DummyEntity::getMetadata()], [DummyEmbeddable::class, DummyEmbeddable::getMetadata()]]));
     $em = $this->getMock(EntityManagerInterface::class);
     $em->method('getMetadataFactory')->willReturn($this->metadataFactory);
     $this->entity = new DummyEntity();
     $this->entity->setId(1);
     $this->entity->setA('1a');
     $this->entity->setB('1b');
     $this->entity->setC('1c');
     $d = new DummyEmbeddable();
     $d->setX(1);
     $d->setY(2);
     $d->setZ(3);
     $this->entity->setD($d);
     $child = new DummyEntity();
     $child->setId(2);
     $child->setA('2a');
     $child->setB('2b');
     $child->setC('2c');
     $d = new DummyEmbeddable();
     $d->setX(21);
     $d->setY(22);
     $d->setZ(23);
     $child->setD($d);
     $this->entity->addChild($child);
     $child = new DummyEntity();
     $child->setId(3);
     $child->setA('3a');
     $child->setB('3b');
     $child->setC('3c');
     $d = new DummyEmbeddable();
     $d->setX(31);
     $d->setY(32);
     $d->setZ(33);
     $child->setD($d);
     $this->entity->addChild($child);
     $subchild = new DummyEntity();
     $subchild->setId(4);
     $subchild->setA('4a');
     $subchild->setB('4b');
     $subchild->setC('4c');
     $d = new DummyEmbeddable();
     $d->setX(41);
     $d->setY(42);
     $d->setZ(43);
     $subchild->setD($d);
     $child->addChild($subchild);
     $this->normalizer = new DoctrineNormalizer(null, null, null, $em);
     $propertyNormalizer = new PropertyNormalizer();
     $serializer = new Serializer([$this->normalizer, $propertyNormalizer]);
     $this->normalizer->setSerializer($serializer);
 }
開發者ID:mihai-stancu,項目名稱:serializer,代碼行數:55,代碼來源:DoctrineNormalizerTest.php

示例4: setUp

 /**
  * @param mixed $classes
  * @return void
  */
 public function setUp()
 {
     $this->doctrine = Zend_Registry::get('container')->getService('doctrine');
     $this->em = $this->doctrine->getEntityManager();
     $this->em->clear();
     $tool = new SchemaTool($this->em);
     $tool->dropDatabase();
     $classes = func_get_args();
     if (!empty($classes)) {
         $metadataFactory = new ClassMetadataFactory();
         $metadataFactory->setEntityManager($this->em);
         $metadataFactory->setCacheDriver(new ArrayCache());
         $metadata = array();
         foreach ((array) $classes as $class) {
             $metadata[] = $metadataFactory->getMetadataFor($class);
         }
         $tool->createSchema($metadata);
     }
 }
開發者ID:nidzix,項目名稱:Newscoop,代碼行數:23,代碼來源:RepositoryTestCase.php

示例5: testGetMetadataForSingleClass

 public function testGetMetadataForSingleClass()
 {
     $mockDriver = new MetadataDriverMock();
     $entityManager = $this->_createEntityManager($mockDriver);
     $conn = $entityManager->getConnection();
     $mockPlatform = $conn->getDatabasePlatform();
     $mockPlatform->setPrefersSequences(true);
     $mockPlatform->setPrefersIdentityColumns(false);
     // Self-made metadata
     $cm1 = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
     $cm1->setPrimaryTable(array('name' => '`group`'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar'));
     // Add a mapped field
     $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
     // and a mapped association
     $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'TestEntity1', 'mappedBy' => 'this'));
     // and an association on the owning side
     $joinColumns = array(array('name' => 'other_id', 'referencedColumnName' => 'id'));
     $cm1->mapOneToOne(array('fieldName' => 'association', 'targetEntity' => 'TestEntity1', 'joinColumns' => $joinColumns));
     // and an id generator type
     $cm1->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_AUTO);
     // SUT
     $cmf = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
     $cmf->setEntityManager($entityManager);
     $cmf->setMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1', $cm1);
     // Prechecks
     $this->assertEquals(array(), $cm1->parentClasses);
     $this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $cm1->inheritanceType);
     $this->assertTrue($cm1->hasField('name'));
     $this->assertEquals(2, count($cm1->associationMappings));
     $this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $cm1->generatorType);
     $this->assertEquals('group', $cm1->table['name']);
     // Go
     $cmMap1 = $cmf->getMetadataFor('Doctrine\\Tests\\ORM\\Mapping\\TestEntity1');
     $this->assertSame($cm1, $cmMap1);
     $this->assertEquals('group', $cmMap1->table['name']);
     $this->assertTrue($cmMap1->table['quoted']);
     $this->assertEquals(array(), $cmMap1->parentClasses);
     $this->assertTrue($cmMap1->hasField('name'));
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:42,代碼來源:ClassMetadataFactoryTest.php

示例6: setUpOrm

 /**
  * Set up entity manager
  *
  * @return Doctrine\ORM\EntityManager
  */
 protected function setUpOrm()
 {
     global $application;
     $doctrine = $application->getBootstrap()->getResource('container')->getService('doctrine');
     $orm = $doctrine->getEntityManager();
     $orm->clear();
     $tool = new SchemaTool($orm);
     $tool->dropDatabase();
     $classes = func_get_args();
     if (!empty($classes)) {
         $metadataFactory = new ClassMetadataFactory();
         $metadataFactory->setEntityManager($orm);
         $metadataFactory->setCacheDriver(new Cache());
         $metadata = array();
         foreach ((array) $classes as $class) {
             $metadata[] = $metadataFactory->getMetadataFor($class);
         }
         $tool->createSchema($metadata);
     }
     return $orm;
 }
開發者ID:nidzix,項目名稱:Newscoop,代碼行數:26,代碼來源:TestCase.php

示例7: testAssertTableColumnsAreNotAddedInManyToMany

 /**
  * @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']);
 }
開發者ID:Herriniaina,項目名稱:iVarotra,代碼行數:14,代碼來源:ResolveTargetEntityListenerTest.php

示例8: testResolveTargetEntityListenerCanResolveTargetEntity

 /**
  * @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']);
 }
開發者ID:dracony,項目名稱:forked-php-orm-benchmark,代碼行數:16,代碼來源:ResolveTargetEntityListenerTest.php

示例9: clear

 /**
  * Clears the EntityManager. All entities that are currently managed
  * by this EntityManager become detached.
  *
  * @param string|null $entityName if given, only entities of this type will get detached
  *
  * @return void
  *
  * @throws ORMInvalidArgumentException                           if a non-null non-string value is given
  * @throws \Doctrine\Common\Persistence\Mapping\MappingException if a $entityName is given, but that entity is not
  *                                                               found in the mappings
  */
 public function clear($entityName = null)
 {
     if (null !== $entityName && !is_string($entityName)) {
         throw ORMInvalidArgumentException::invalidEntityName($entityName);
     }
     $this->unitOfWork->clear(null === $entityName ? null : $this->metadataFactory->getMetadataFor($entityName)->getName());
 }
開發者ID:AdactiveSAS,項目名稱:doctrine2,代碼行數:19,代碼來源:EntityManager.php

示例10: storeCollectionCache

 /**
  * {@inheritdoc}
  */
 public function storeCollectionCache(CollectionCacheKey $key, $elements)
 {
     /* @var $targetPersister CachedEntityPersister */
     $associationMapping = $this->sourceEntity->associationMappings[$key->association];
     $targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName);
     $targetRegion = $targetPersister->getCacheRegion();
     $targetHydrator = $targetPersister->getEntityHydrator();
     // Only preserve ordering if association configured it
     if (!(isset($associationMapping['indexBy']) && $associationMapping['indexBy'])) {
         // Elements may be an array or a Collection
         $elements = array_values(is_array($elements) ? $elements : $elements->getValues());
     }
     $entry = $this->hydrator->buildCacheEntry($this->targetEntity, $key, $elements);
     foreach ($entry->identifiers as $index => $entityKey) {
         if ($targetRegion->contains($entityKey)) {
             continue;
         }
         $class = $this->targetEntity;
         $className = ClassUtils::getClass($elements[$index]);
         if ($className !== $this->targetEntity->name) {
             $class = $this->metadataFactory->getMetadataFor($className);
         }
         $entity = $elements[$index];
         $entityEntry = $targetHydrator->buildCacheEntry($class, $entityKey, $entity);
         $targetRegion->put($entityKey, $entityEntry);
     }
     $cached = $this->region->put($key, $entry);
     if ($this->cacheLogger && $cached) {
         $this->cacheLogger->collectionCachePut($this->regionName, $key);
     }
 }
開發者ID:StoshSeb,項目名稱:doctrine2,代碼行數:34,代碼來源:AbstractCollectionPersister.php

示例11: getIdentifierFromArray

 /**
  * @param string $class
  * @param array  $array
  *
  * @return array
  */
 protected function getIdentifierFromArray($class, $array)
 {
     $meta = $this->entityMetadataFactory->getMetadataFor($class);
     $fields = $meta->getIdentifierFieldNames();
     $ids = array();
     foreach ($fields as $field) {
         if (isset($array[$field])) {
             $ids[$field] = $array[$field];
         } else {
             $tmp = $array;
             $parts = explode('.', $field);
             foreach ($parts as $part) {
                 if (isset($tmp[$part])) {
                     if (is_array($tmp[$part])) {
                         $tmp = $tmp[$part];
                     } else {
                         $ids[$field] = $tmp[$part];
                         break;
                     }
                 }
             }
         }
     }
     return $ids;
 }
開發者ID:mihai-stancu,項目名稱:serializer,代碼行數:31,代碼來源:DoctrineNormalizer.php

示例12: storeCollectionCache

 /**
  * {@inheritdoc}
  */
 public function storeCollectionCache(CollectionCacheKey $key, $elements)
 {
     /* @var $targetPersister CachedEntityPersister */
     $targetPersister = $this->uow->getEntityPersister($this->targetEntity->rootEntityName);
     $targetRegion = $targetPersister->getCacheRegion();
     $targetHydrator = $targetPersister->getEntityHydrator();
     $entry = $this->hydrator->buildCacheEntry($this->targetEntity, $key, $elements);
     foreach ($entry->identifiers as $index => $entityKey) {
         if ($targetRegion->contains($entityKey)) {
             continue;
         }
         $class = $this->targetEntity;
         $className = ClassUtils::getClass($elements[$index]);
         if ($className !== $this->targetEntity->name) {
             $class = $this->metadataFactory->getMetadataFor($className);
         }
         $entity = $elements[$index];
         $entityEntry = $targetHydrator->buildCacheEntry($class, $entityKey, $entity);
         $targetRegion->put($entityKey, $entityEntry);
     }
     $cached = $this->region->put($key, $entry);
     if ($this->cacheLogger && $cached) {
         $this->cacheLogger->collectionCachePut($this->regionName, $key);
     }
 }
開發者ID:BozzaCoon,項目名稱:SPHERE-Framework,代碼行數:28,代碼來源:AbstractCollectionPersister.php

示例13: setMetadataFor

 /**
  * {@inheritdoc}
  */
 public function setMetadataFor($className, $class)
 {
     $cacheDriver = $this->getCacheDriver();
     if (null !== $cacheDriver) {
         $cacheDriver->save($className . $this->cacheSalt, $class, null);
     }
     parent::setMetadataFor($className, $class);
 }
開發者ID:northdakota,項目名稱:platform,代碼行數:11,代碼來源:ExtendClassMetadataFactory.php

示例14: testMappedSuperclassIndex

 /**
  * Ensure indexes are inherited from the mapped superclass.
  *
  * @group DDC-3418
  */
 public function testMappedSuperclassIndex()
 {
     $class = $this->cmf->getMetadataFor(__NAMESPACE__ . '\\EntityIndexSubClass');
     /* @var $class ClassMetadataInfo */
     $this->assertArrayHasKey('mapped1', $class->fieldMappings);
     $this->assertArrayHasKey('IDX_NAME_INDEX', $class->table['uniqueConstraints']);
     $this->assertArrayHasKey('IDX_MAPPED1_INDEX', $class->table['uniqueConstraints']);
     $this->assertArrayHasKey('IDX_MAPPED2_INDEX', $class->table['indexes']);
 }
開發者ID:selimcr,項目名稱:servigases,代碼行數:14,代碼來源:BasicInheritanceMappingTest.php

示例15: prepareEntityRepository

 /**
  * Prepare repository for specific entity
  *
  * @param  string           $entityName
  * @param  array            $entities
  * @param  array            $entityIds
  * @return EntityRepository
  */
 protected function prepareEntityRepository($entityName, array $entities, array $entityIds)
 {
     $query = $this->getMockForAbstractClass('Doctrine\\ORM\\AbstractQuery', array($this->entityManager), '', true, true, true, array('getResult'));
     $query->expects($this->once())->method('getResult')->will($this->returnValue($entities));
     $queryBuilder = $this->getMock('Doctrine\\ORM\\QueryBuilder', array('where', 'getQuery'), array($this->entityManager));
     $queryBuilder->expects($this->once())->method('where')->with(new Func('e.id IN', $entityIds));
     $queryBuilder->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     $repository = $this->getMock('Doctrine\\ORM\\EntityRepository', array('createQueryBuilder'), array($this->entityManager, $this->stubMetadata->getMetadataFor($entityName)));
     $repository->expects($this->any())->method('createQueryBuilder')->with('e')->will($this->returnValue($queryBuilder));
     return $repository;
 }
開發者ID:xamin123,項目名稱:platform,代碼行數:19,代碼來源:ResultFormatterTest.php


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