本文整理汇总了PHP中Doctrine\ORM\Tools\EntityGenerator::generateEntityClass方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityGenerator::generateEntityClass方法的具体用法?PHP EntityGenerator::generateEntityClass怎么用?PHP EntityGenerator::generateEntityClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\EntityGenerator
的用法示例。
在下文中一共展示了EntityGenerator::generateEntityClass方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportClassMetadata
/**
* {@inheritdoc}
*/
public function exportClassMetadata(ClassMetadataInfo $metadata)
{
if (!$this->_entityGenerator) {
throw new \RuntimeException('For the AnnotationExporter you must set an EntityGenerator instance with the setEntityGenerator() method.');
}
$this->_entityGenerator->setGenerateAnnotations(true);
$this->_entityGenerator->setGenerateStubMethods(false);
$this->_entityGenerator->setRegenerateEntityIfExists(false);
$this->_entityGenerator->setUpdateEntityIfExists(false);
return $this->_entityGenerator->generateEntityClass($metadata);
}
示例2: generateEntityClass
public function generateEntityClass(ClassMetadataInfo $metadata)
{
static::swap();
$result = parent::generateEntityClass($metadata);
static::swap();
return $result;
}
示例3: generate
public function generate($jsonSchema)
{
$schema = json_decode($jsonSchema, true);
if (!isset($schema['type']) && $schema['type'] !== 'object') {
throw new \RuntimeException("Unable to process the schema");
}
if (!isset($schema['title'])) {
throw new \RuntimeException("title property must be defined");
}
// TODO investigate implementation via ClassMetadataBuilder
$className = $schema['title'];
$medatadata = new ClassMetadata($this->getNamespace() . '\\' . $className);
if (isset($schema['properties'])) {
foreach ($schema['properties'] as $name => $definition) {
$type = $definition['type'];
$nullable = isset($schema['required']) ? !in_array($name, $schema['required']) : true;
$medatadata->mapField(['fieldName' => $name, 'type' => $type, 'nullable' => $nullable, 'options' => []]);
}
}
$filename = sprintf("%s/%s/%s.php", $this->getPath(), join('/', explode('\\', $this->getNamespace())), $className);
mkdir(dirname($filename), 0777, true);
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(true);
file_put_contents($filename, $generator->generateEntityClass($medatadata));
}
示例4: generateClass
/**
* @return bool
* @throws \Exception
*/
public function generateClass()
{
$metadata = $this->getMetaData();
$this->setClassName($metadata->name);
// setting the namespace
$metadata->name = $this->getNamespace() . '\\' . $metadata->name;
//generate the basic class-code
if (!($this->generatedCode = $this->entityGenerator->generateEntityClass($metadata))) {
throw new \Exception('Entity class could not be created');
}
// TableAnnotation-Update if a Database is given
if (isset($this->database)) {
$this->updateTableAnnotation();
}
$this->generateUseStatements();
$this->generateMethods();
$this->writeFile();
return true;
}
示例5: generateEntityClass
/**
* {@inheritdoc}
*/
public function generateEntityClass(ClassMetadataInfo $metadata)
{
$code = parent::generateEntityClass($metadata);
$class = new \ReflectionClass('Doctrine\\ORM\\Tools\\EntityGenerator');
$spacesProperty = $class->getProperty('spaces');
$spacesProperty->setAccessible(true);
$prefixCodeWithSpacesMethod = $class->getMethod('prefixCodeWithSpaces');
$prefixCodeWithSpacesMethod->setAccessible(true);
$code = str_replace(array('<constants>'), array($prefixCodeWithSpacesMethod->invoke($this, $this->generateConstant($metadata))), $code);
return str_replace('<spaces>', $spacesProperty->getValue($this), $code);
}