本文整理汇总了PHP中Doctrine\ORM\Tools\EntityGenerator::writeEntityClass方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityGenerator::writeEntityClass方法的具体用法?PHP EntityGenerator::writeEntityClass怎么用?PHP EntityGenerator::writeEntityClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\EntityGenerator
的用法示例。
在下文中一共展示了EntityGenerator::writeEntityClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeEntityClass
/**
* @param string $className
* @param string $newClassName
* @return string
*/
private function writeEntityClass($className, $newClassName)
{
$cmf = new ClassMetadataFactory();
$em = $this->_getTestEntityManager();
$cmf->setEntityManager($em);
$metadata = $cmf->getMetadataFor($className);
$metadata->namespace = $this->_namespace;
$metadata->name = $newClassName;
$metadata->customRepositoryClassName = $newClassName . "Repository";
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
require $this->_tmpDir . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $newClassName) . ".php";
}
示例2: testRegenerateEntityClass
public function testRegenerateEntityClass()
{
$metadata = $this->generateBookEntityFixture();
$this->loadEntityClass($metadata);
$className = basename(str_replace('\\', '/', $metadata->name));
$path = $this->_tmpDir . '/' . $this->_namespace . '/' . $className . '.php';
$classTest = file_get_contents($path);
$this->_generator->setRegenerateEntityIfExists(true);
$this->_generator->setBackupExisting(false);
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
$classNew = file_get_contents($path);
$this->assertSame($classTest, $classNew);
}
示例3: testGenerateEntityWithSequenceGenerator
/**
* @group DDC-1784
*/
public function testGenerateEntityWithSequenceGenerator()
{
$metadata = new ClassMetadataInfo($this->_namespace . '\\DDC1784Entity');
$metadata->namespace = $this->_namespace;
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
$metadata->setSequenceGeneratorDefinition(array('sequenceName' => 'DDC1784_ID_SEQ', 'allocationSize' => 1, 'initialValue' => 2));
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
$filename = $this->_tmpDir . DIRECTORY_SEPARATOR . $this->_namespace . DIRECTORY_SEPARATOR . 'DDC1784Entity.php';
$this->assertFileExists($filename);
require_once $filename;
$reflection = new \ReflectionProperty($metadata->name, 'id');
$docComment = $reflection->getDocComment();
$this->assertContains('@Id', $docComment);
$this->assertContains('@Column(name="id", type="integer")', $docComment);
$this->assertContains('@GeneratedValue(strategy="SEQUENCE")', $docComment);
$this->assertContains('@SequenceGenerator(sequenceName="DDC1784_ID_SEQ", allocationSize=1, initialValue=2)', $docComment);
}
示例4: testGenerateEntityWithMultipleInverseJoinColumns
/**
* @group DDC-2079
*/
public function testGenerateEntityWithMultipleInverseJoinColumns()
{
$metadata = new ClassMetadataInfo($this->_namespace . '\\DDC2079Entity');
$metadata->namespace = $this->_namespace;
$metadata->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true));
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE);
$metadata->mapManyToMany(array('fieldName' => 'centroCustos', 'targetEntity' => 'DDC2079CentroCusto', 'joinTable' => array('name' => 'unidade_centro_custo', 'joinColumns' => array(array('name' => 'idorcamento', 'referencedColumnName' => 'idorcamento'), array('name' => 'idunidade', 'referencedColumnName' => 'idunidade')), 'inverseJoinColumns' => array(array('name' => 'idcentrocusto', 'referencedColumnName' => 'idcentrocusto'), array('name' => 'idpais', 'referencedColumnName' => 'idpais')))));
$this->_generator->writeEntityClass($metadata, $this->_tmpDir);
$filename = $this->_tmpDir . DIRECTORY_SEPARATOR . $this->_namespace . DIRECTORY_SEPARATOR . 'DDC2079Entity.php';
$this->assertFileExists($filename);
require_once $filename;
$property = new \ReflectionProperty($metadata->name, 'centroCustos');
$docComment = $property->getDocComment();
//joinColumns
$this->assertContains('@JoinColumn(name="idorcamento", referencedColumnName="idorcamento"),', $docComment);
$this->assertContains('@JoinColumn(name="idunidade", referencedColumnName="idunidade")', $docComment);
//inverseJoinColumns
$this->assertContains('@JoinColumn(name="idcentrocusto", referencedColumnName="idcentrocusto"),', $docComment);
$this->assertContains('@JoinColumn(name="idpais", referencedColumnName="idpais")', $docComment);
}
示例5: generate
public function generate($parameters)
{
if (!$this->isInitialized) {
throw new \RuntimeException('Entity generator needs to be initialized first in order to generate');
}
$moduleName = $this->moduleName;
$parentClassName = $this->parentClassName;
$this->classNames = $parameters->classNames;
$classNames = $this->classNames;
$outputList = array();
$metadatas = array();
foreach ($classNames as $className) {
if (in_array($className, $this->driver->getAllClassNames())) {
$classNameWithNamespace = $this->getNamespacedClassName($className);
$this->namespacedClassNames[$className] = $classNameWithNamespace;
$realClassNameWithNamespace = $this->composeFullClassName($classNameWithNamespace);
$realClassName = $this->getClassNameFromNamespacedClassName($classNameWithNamespace);
$namespace = $this->getNamespaceFromNamespacedClassName($realClassNameWithNamespace, $realClassName);
$metadata = new \Doctrine\ORM\Mapping\ClassMetadataInfo($className);
$this->driver->loadMetadataForClass($className, $metadata);
$metadata = $this->fixMetadata($metadata);
$outputList[] = array('outputDirectory' => $this->generatedEntityOutputDirectory, 'entityNamespace' => $this->entityNamespace, 'entityName' => $className, 'className' => $realClassName);
$metadata->name = $realClassNameWithNamespace;
$metadata->namespace = $namespace;
$metadatas[] = $metadata;
echo $namespace . '\\' . $realClassName . '<br>';
}
}
if (count($metadatas) > 0) {
$this->initGenerator();
if ($this->parentClassName != null) {
if (!file_exists($this->generatedEntityOutputDirectory . '/' . $this->parentClassName . '.php')) {
$parentMetadata = new \Doctrine\ORM\Mapping\ClassMetadataInfo($this->parentClassName);
$parentMetadata->name = $this->composeFullClassName($this->parentClassName);
$this->generator->writeEntityClass($parentMetadata, $this->generatedEntityOutputDirectory);
}
}
$this->generator->generate($metadatas, $this->generatedEntityOutputDirectory);
}
return $outputList;
}