本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::initializeReflection方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::initializeReflection方法的具体用法?PHP ClassMetadata::initializeReflection怎么用?PHP ClassMetadata::initializeReflection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::initializeReflection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: testColumnWithMissingTypeDefaultsToString
/**
* @group DDC-268
*/
public function testColumnWithMissingTypeDefaultsToString()
{
$cm = new ClassMetadata('Doctrine\\Tests\\ORM\\Mapping\\ColumnWithoutType');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$annotationDriver = $this->_loadDriver();
$annotationDriver->loadMetadataForClass('Doctrine\\Tests\\ORM\\Mapping\\InvalidColumn', $cm);
$this->assertEquals('string', $cm->fieldMappings['id']['type']);
}
示例3: 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.");
}
示例4: createClassMetadata
public function createClassMetadata($entityClassName)
{
$mappingDriver = $this->_loadDriver();
$class = new ClassMetadata($entityClassName);
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$mappingDriver->loadMetadataForClass($entityClassName, $class);
return $class;
}
示例5: testGetTableName
public function testGetTableName()
{
$cm = $this->createClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$cm->setPrimaryTable(array('name' => '`cms_user`'));
$this->assertEquals('"cms_user"', $this->strategy->getTableName($cm, $this->platform));
$cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$cm->setPrimaryTable(array('name' => 'cms_user'));
$this->assertEquals('cms_user', $this->strategy->getTableName($cm, $this->platform));
}
示例6: testClassTableInheritanceDiscriminatorMap
public function testClassTableInheritanceDiscriminatorMap()
{
$className = 'Doctrine\\Tests\\ORM\\Mapping\\CTI';
$mappingDriver = $this->_loadDriver();
$class = new ClassMetadata($className);
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$mappingDriver->loadMetadataForClass($className, $class);
$expectedMap = array('foo' => 'Doctrine\\Tests\\ORM\\Mapping\\CTIFoo', 'bar' => 'Doctrine\\Tests\\ORM\\Mapping\\CTIBar', 'baz' => 'Doctrine\\Tests\\ORM\\Mapping\\CTIBaz');
$this->assertEquals(3, count($class->discriminatorMap));
$this->assertEquals($expectedMap, $class->discriminatorMap);
}
示例7: createClassMetadata
public function createClassMetadata(GClass $gClass)
{
// da wir gClass mehrmals im Test evalen könnten, erzeugen wir einen unique hash für den classname und übergeben den
// der class metadata
$className = uniqid($gClass->getClassName());
$gClass->setClassName($className);
$gClass->createDocBlock()->addAnnotation(Annotation::createDC('Entity'));
$classWriter = new ClassWriter($gClass);
$classWriter->setUseStyle('lines');
$classWriter->addImport(new GClass('Doctrine\\ORM\\Mapping'), 'ORM');
// braucht einen AnnotationReader nicht SimpleAnnotationReader
$classWriter->write($file = $this->newFile('entity.' . $gClass->getClassName() . '.php'));
require $file;
$cm = new ClassMetadata($gClass->getFQN());
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$this->annotationDriver->loadMetadataForClass($gClass->getFQN(), $cm);
$file->delete();
return $cm;
}
示例8: 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'));
}
示例9: testDoctrineProxy
public function testDoctrineProxy()
{
$className = 'Saxulum\\Tests\\Accessor\\Fixtures\\Entity\\Entity';
$proxyDirectory = __DIR__ . '/../proxy/';
$proxyNamespace = 'Proxy';
$proxyClassName = $proxyNamespace . '\\__CG__\\' . $className;
$proxyClassFilename = $proxyDirectory . str_replace('\\', '_', $proxyClassName) . '.php';
if (!is_dir($proxyDirectory)) {
mkdir($proxyDirectory, 0777, true);
}
$reflectionService = new RuntimeReflectionService();
$classMetadata = new ClassMetadata(get_class(new Entity()));
$classMetadata->initializeReflection($reflectionService);
$proxyGenerator = new ProxyGenerator($proxyDirectory, $proxyNamespace);
$proxyGenerator->generateProxyClass($classMetadata, $proxyClassFilename);
require $proxyClassFilename;
/** @var Entity $proxy */
$proxy = new $proxyClassName();
$proxy->setName('test');
$this->assertEquals('test', $proxy->getName());
unlink($proxyClassFilename);
//rmdir($proxyDirectory);
}
示例10: testInvalidCascade
/**
* @group DDC-1746
*/
public function testInvalidCascade()
{
$cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$this->setExpectedException("Doctrine\\ORM\\Mapping\\MappingException", "Invalid cascade option(s) specified: 'invalid'. Only 'remove', 'persist', 'refresh', 'merge' and 'detach' are allowed.");
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass', 'cascade' => array('invalid')));
}
示例11: testTargetEntityNotFound
/**
* @group ImproveErrorMessages
*/
public function testTargetEntityNotFound()
{
$cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$cm->mapManyToOne(array('fieldName' => 'address', 'targetEntity' => 'UnknownClass'));
$this->setExpectedException("Doctrine\\ORM\\Mapping\\MappingException", "The target-entity Doctrine\\Tests\\Models\\CMS\\UnknownClass cannot be found in 'Doctrine\\Tests\\Models\\CMS\\CmsUser#address'.");
$cm->validateAssocations();
}
示例12: getDirectlyAssociatedEntities
/**
* Returns the class names of additional entities that are directly associated with
* one of the entities that is explicitly mentioned in the given configuration.
*
* @param Configuration $config
* @param string[] $entityClasses Classes whose associations are checked.
* @return string[] Associated entity classes.
*/
protected function getDirectlyAssociatedEntities(Configuration $config, $entityClasses)
{
if (count($entityClasses) === 0) {
return array();
}
$associatedEntities = array();
foreach ($entityClasses as $entityClass) {
/* @var $entityClass string */
$metadata = new ClassMetadata($entityClass);
$metadata->initializeReflection($this->reflectionService);
$config->getMetadataDriverImpl()->loadMetadataForClass($entityClass, $metadata);
foreach ($metadata->getAssociationNames() as $name) {
/* @var $name string */
$associatedEntity = $metadata->getAssociationTargetClass($name);
$associatedEntities[] = $metadata->fullyQualifiedClassName($associatedEntity);
}
if (count($metadata->discriminatorMap) > 0) {
$childClasses = array_values($metadata->discriminatorMap);
$associatedEntities = array_merge($associatedEntities, $childClasses);
}
// Add parent classes that are involved in some kind of entity inheritance.
foreach ($this->reflectionService->getParentClasses($entityClass) as $parentClass) {
if (!$config->getMetadataDriverImpl()->isTransient($parentClass)) {
$associatedEntities[] = $parentClass;
}
}
}
return array_unique($associatedEntities);
}
示例13: createClassMetadata
/**
* @param string $className
* @return \Doctrine\ORM\Mapping\ClassMetadata
*/
private function createClassMetadata($className)
{
$class = new ClassMetadata($className);
$class->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
return $class;
}
示例14: setUp
public function setUp()
{
$this->cm = new ClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser');
$this->cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$this->builder = new ClassMetadataBuilder($this->cm);
}
示例15: testCanInstantiateInternalPhpClassSubclass
/**
* @group DDC-3120
*/
public function testCanInstantiateInternalPhpClassSubclass()
{
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService());
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
}