当前位置: 首页>>代码示例>>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;未经允许,请勿转载。