本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadataFactory::getMetadataFor方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataFactory::getMetadataFor方法的具体用法?PHP ClassMetadataFactory::getMetadataFor怎么用?PHP ClassMetadataFactory::getMetadataFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadataFactory
的用法示例。
在下文中一共展示了ClassMetadataFactory::getMetadataFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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']);
}
示例2: 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']);
}
示例3: 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());
}
示例4: 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'));
}
示例5: 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;
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: 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']);
}
示例9: 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']);
}
示例10: 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;
}
示例11: getMetadataFor
/**
* {@inheritdoc}
*/
public function getMetadataFor($className)
{
if ($logger = $this->getProfilingLogger()) {
$logger->startGetMetadataFor();
$result = parent::getMetadataFor($className);
$logger->stopGetMetadataFor();
return $result;
} else {
return parent::getMetadataFor($className);
}
}
示例12: getReference
/**
* Gets a reference to the entity identified by the given type and identifier
* without actually loading it.
*
* If partial objects are allowed, this method will return a partial object that only
* has its identifier populated. Otherwise a proxy is returned that automatically
* loads itself on first access.
*
* @return object The entity reference.
*/
public function getReference($entityName, $identifier)
{
$class = $this->_metadataFactory->getMetadataFor($entityName);
// Check identity map first, if its already in there just return it.
if ($entity = $this->_unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
return $entity;
}
if (!is_array($identifier)) {
$identifier = array($class->identifier[0] => $identifier);
}
$entity = $this->_proxyFactory->getProxy($class->name, $identifier);
$this->_unitOfWork->registerManaged($entity, $identifier, array());
return $entity;
}
示例13: getPartialReference
/**
* Gets a partial reference to the entity identified by the given type and identifier
* without actually loading it, if the entity is not yet loaded.
*
* The returned reference may be a partial object if the entity is not yet loaded/managed.
* If it is a partial object it will not initialize the rest of the entity state on access.
* Thus you can only ever safely access the identifier of an entity obtained through
* this method.
*
* The use-cases for partial references involve maintaining bidirectional associations
* without loading one side of the association or to update an entity without loading it.
* Note, however, that in the latter case the original (persistent) entity data will
* never be visible to the application (especially not event listeners) as it will
* never be loaded in the first place.
*
* @param string $entityName The name of the entity type.
* @param mixed $identifier The entity identifier.
* @return object The (partial) entity reference.
*/
public function getPartialReference($entityName, $identifier)
{
$class = $this->metadataFactory->getMetadataFor(ltrim($entityName, '\\'));
// Check identity map first, if its already in there just return it.
if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
return $entity instanceof $class->name ? $entity : null;
}
if (!is_array($identifier)) {
$identifier = array($class->identifier[0] => $identifier);
}
$entity = $class->newInstance();
$class->setIdentifierValues($entity, $identifier);
$this->unitOfWork->registerManaged($entity, $identifier, array());
return $entity;
}
示例14: 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);
}
}
示例15: 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'));
}