本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadataFactory::setMetadataFor方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataFactory::setMetadataFor方法的具体用法?PHP ClassMetadataFactory::setMetadataFor怎么用?PHP ClassMetadataFactory::setMetadataFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadataFactory
的用法示例。
在下文中一共展示了ClassMetadataFactory::setMetadataFor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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'));
}
示例3: setMetadataFor
/**
* {@inheritdoc}
*/
public function setMetadataFor($className, $class)
{
$cacheDriver = $this->getCacheDriver();
if (null !== $cacheDriver) {
$cacheDriver->save($className . $this->cacheSalt, $class, null);
}
parent::setMetadataFor($className, $class);
}
示例4: 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'));
}
示例5: setMetadataFor
public function setMetadataFor($className, $class)
{
$this->getCacheDriver()->save($className . $this->cacheSalt, $class, null);
parent::setMetadataFor($className, $class);
}