2010-03-19 00:38:42 +03:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Doctrine\ORM\Tools;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo,
|
2010-03-20 01:38:45 +03:00
|
|
|
Doctrine\ORM\Mapping\AssociationMapping,
|
|
|
|
Doctrine\Common\Util\Inflector;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic class used to generate PHP5 entity classes from ClassMetadataInfo instances
|
|
|
|
*
|
|
|
|
* [php]
|
|
|
|
* $classes = $em->getClassMetadataFactory()->getAllMetadata();
|
|
|
|
*
|
|
|
|
* $generator = new \Doctrine\ORM\Tools\EntityGenerator();
|
|
|
|
* $generator->setGenerateAnnotations(true);
|
|
|
|
* $generator->setGenerateStubMethods(true);
|
|
|
|
* $generator->setRegenerateEntityIfExists(false);
|
|
|
|
* $generator->setUpdateEntityIfExists(true);
|
|
|
|
* $generator->generate($classes, '/path/to/generate/entities');
|
|
|
|
*
|
|
|
|
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
|
* @link www.doctrine-project.org
|
|
|
|
* @since 2.0
|
|
|
|
* @version $Revision$
|
|
|
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
|
|
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
|
|
|
* @author Jonathan Wage <jonwage@gmail.com>
|
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
*/
|
|
|
|
class EntityGenerator
|
|
|
|
{
|
|
|
|
/** The extension to use for written php files */
|
|
|
|
private $_extension = '.php';
|
|
|
|
|
|
|
|
/** Whether or not the current ClassMetadataInfo instance is new or old */
|
2010-03-19 07:19:15 +03:00
|
|
|
private $_isNew = true;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-19 01:35:16 +03:00
|
|
|
/** If isNew is false then this variable contains instance of ReflectionClass for current entity */
|
|
|
|
private $_reflection;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
|
|
|
/** Number of spaces to use for indention in generated code */
|
|
|
|
private $_numSpaces = 4;
|
|
|
|
|
|
|
|
/** The actual spaces to use for indention */
|
|
|
|
private $_spaces = ' ';
|
|
|
|
|
|
|
|
/** The class all generated entities should extend */
|
|
|
|
private $_classToExtend;
|
|
|
|
|
|
|
|
/** Whether or not to generation annotations */
|
|
|
|
private $_generateAnnotations = false;
|
|
|
|
|
|
|
|
/** Whether or not to generated sub methods */
|
2010-03-19 07:19:15 +03:00
|
|
|
private $_generateEntityStubMethods = false;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
|
|
|
/** Whether or not to update the entity class if it exists already */
|
|
|
|
private $_updateEntityIfExists = false;
|
|
|
|
|
|
|
|
/** Whether or not to re-generate entity class if it exists already */
|
|
|
|
private $_regenerateEntityIfExists = false;
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private static $_classTemplate =
|
2010-03-19 00:38:42 +03:00
|
|
|
'<?php
|
|
|
|
|
|
|
|
<namespace><use>
|
2010-03-20 01:47:34 +03:00
|
|
|
|
2010-03-19 00:38:42 +03:00
|
|
|
<entityAnnotation>
|
|
|
|
<entityClassName>
|
|
|
|
{
|
|
|
|
<entityBody>
|
|
|
|
}';
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private static $_getMethodTemplate =
|
|
|
|
'/**
|
2010-03-20 01:47:34 +03:00
|
|
|
* <description>
|
|
|
|
*
|
|
|
|
* @return <variableType>$<variableName>
|
|
|
|
*/
|
2010-03-20 01:38:45 +03:00
|
|
|
public function <methodName>()
|
|
|
|
{
|
|
|
|
return $this-><fieldName>;
|
|
|
|
}';
|
|
|
|
|
|
|
|
private static $_setMethodTemplate =
|
|
|
|
'/**
|
2010-03-20 01:47:34 +03:00
|
|
|
* <description>
|
|
|
|
*
|
|
|
|
* @param <variableType>$<variableName>
|
|
|
|
*/
|
2010-03-20 01:38:45 +03:00
|
|
|
public function <methodName>(<methodTypeHint>$<variableName>)
|
|
|
|
{
|
|
|
|
$this-><fieldName> = $<variableName>;
|
|
|
|
}';
|
|
|
|
|
|
|
|
private static $_addMethodTemplate =
|
|
|
|
'/**
|
2010-03-20 01:47:34 +03:00
|
|
|
* <description>
|
|
|
|
*
|
|
|
|
* @param <variableType>$<variableName>
|
|
|
|
*/
|
2010-03-20 01:38:45 +03:00
|
|
|
public function <methodName>(<methodTypeHint>$<variableName>)
|
|
|
|
{
|
|
|
|
$this-><fieldName>[] = $<variableName>;
|
|
|
|
}';
|
|
|
|
|
|
|
|
private static $_lifecycleCallbackMethodTemplate =
|
|
|
|
'/**
|
2010-03-20 01:47:34 +03:00
|
|
|
* @<name>
|
|
|
|
*/
|
2010-03-20 01:38:45 +03:00
|
|
|
public function <methodName>()
|
|
|
|
{
|
|
|
|
// Add your code here
|
|
|
|
}';
|
|
|
|
|
2010-03-19 00:38:42 +03:00
|
|
|
/**
|
|
|
|
* Generate and write entity classes for the given array of ClassMetadataInfo instances
|
|
|
|
*
|
|
|
|
* @param array $metadatas
|
|
|
|
* @param string $outputDirectory
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function generate(array $metadatas, $outputDirectory)
|
|
|
|
{
|
|
|
|
foreach ($metadatas as $metadata) {
|
|
|
|
$this->writeEntityClass($metadata, $outputDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generated and write entity class to disk for the given ClassMetadataInfo instance
|
|
|
|
*
|
|
|
|
* @param ClassMetadataInfo $metadata
|
|
|
|
* @param string $outputDirectory
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
|
|
|
|
{
|
|
|
|
$path = $outputDirectory . '/' . str_replace('\\', DIRECTORY_SEPARATOR, $metadata->name) . $this->_extension;
|
|
|
|
$dir = dirname($path);
|
|
|
|
if ( ! is_dir($dir)) {
|
|
|
|
mkdir($dir, 0777, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_isNew = ! file_exists($path);
|
|
|
|
|
2010-03-19 01:35:16 +03:00
|
|
|
if ( ! $this->_isNew) {
|
|
|
|
require_once $path;
|
|
|
|
$this->_reflection = new \ReflectionClass($metadata->name);
|
|
|
|
}
|
|
|
|
|
2010-03-19 00:38:42 +03:00
|
|
|
// If entity doesn't exist or we're re-generating the entities entirely
|
|
|
|
if ($this->_isNew || ( ! $this->_isNew && $this->_regenerateEntityIfExists)) {
|
|
|
|
file_put_contents($path, $this->generateEntityClass($metadata));
|
|
|
|
|
|
|
|
// If entity exists and we're allowed to update the entity class
|
|
|
|
} else if ( ! $this->_isNew && $this->_updateEntityIfExists) {
|
|
|
|
file_put_contents($path, $this->generateUpdatedEntityClass($metadata, $path));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance
|
|
|
|
*
|
|
|
|
* @param ClassMetadataInfo $metadata
|
|
|
|
* @return string $code
|
|
|
|
*/
|
|
|
|
public function generateEntityClass(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
$placeHolders = array(
|
|
|
|
'<namespace>',
|
|
|
|
'<use>',
|
|
|
|
'<entityAnnotation>',
|
|
|
|
'<entityClassName>',
|
|
|
|
'<entityBody>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$replacements = array(
|
|
|
|
$this->_generateEntityNamespace($metadata),
|
|
|
|
$this->_generateEntityUse($metadata),
|
2010-03-20 01:38:45 +03:00
|
|
|
$this->_generateEntityDocBlock($metadata),
|
2010-03-19 00:38:42 +03:00
|
|
|
$this->_generateEntityClassName($metadata),
|
|
|
|
$this->_generateEntityBody($metadata)
|
|
|
|
);
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$code = str_replace($placeHolders, $replacements, self::$_classTemplate);
|
2010-03-19 00:38:42 +03:00
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the updated code for the given ClassMetadataInfo and entity at path
|
|
|
|
*
|
|
|
|
* @param ClassMetadataInfo $metadata
|
|
|
|
* @param string $path
|
|
|
|
* @return string $code;
|
|
|
|
*/
|
|
|
|
public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path)
|
|
|
|
{
|
2010-03-19 01:35:16 +03:00
|
|
|
$currentCode = file_get_contents($path);
|
2010-03-19 00:38:42 +03:00
|
|
|
|
|
|
|
$body = $this->_generateEntityBody($metadata);
|
|
|
|
|
2010-03-19 01:35:16 +03:00
|
|
|
$last = strrpos($currentCode, '}');
|
|
|
|
$code = substr($currentCode, 0, $last) . $body . '}';
|
2010-03-19 00:38:42 +03:00
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of spaces the exported class should have
|
|
|
|
*
|
|
|
|
* @param integer $numSpaces
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setNumSpaces($numSpaces)
|
|
|
|
{
|
|
|
|
$this->_spaces = str_repeat(' ', $numSpaces);
|
|
|
|
$this->_numSpaces = $numSpaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the extension to use when writing php files to disk
|
|
|
|
*
|
|
|
|
* @param string $extension
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setExtension($extension)
|
|
|
|
{
|
|
|
|
$this->_extension = $extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the name of the class the generated classes should extend from
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setClassToExtend($classToExtend)
|
|
|
|
{
|
|
|
|
$this->_classToExtend = $classToExtend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether or not to generate annotations for the entity
|
|
|
|
*
|
|
|
|
* @param bool $bool
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setGenerateAnnotations($bool)
|
|
|
|
{
|
|
|
|
$this->_generateAnnotations = $bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether or not to try and update the entity if it already exists
|
|
|
|
*
|
|
|
|
* @param bool $bool
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUpdateEntityIfExists($bool)
|
|
|
|
{
|
|
|
|
$this->_updateEntityIfExists = $bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether or not to regenerate the entity if it exists
|
|
|
|
*
|
|
|
|
* @param bool $bool
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setRegenerateEntityIfExists($bool)
|
|
|
|
{
|
|
|
|
$this->_regenerateEntityIfExists = $bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set whether or not to generate stub methods for the entity
|
|
|
|
*
|
|
|
|
* @param bool $bool
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setGenerateStubMethods($bool)
|
|
|
|
{
|
2010-03-19 07:19:15 +03:00
|
|
|
$this->_generateEntityStubMethods = $bool;
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityNamespace(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
if ($this->_hasNamespace($metadata)) {
|
|
|
|
return 'namespace ' . $this->_getNamespace($metadata) .';';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityUse(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
if ($this->_extendsClass()) {
|
|
|
|
return "\n\nuse " . $this->_getClassToExtendNamespace().";\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityClassName(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
return 'class ' . $this->_getClassName($metadata) .
|
2010-03-28 21:46:23 +04:00
|
|
|
($this->_extendsClass() ? ' extends ' . $this->_getClassToExtendName() : null);
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityBody(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
$fieldMappingProperties = $this->_generateEntityFieldMappingProperties($metadata);
|
|
|
|
$associationMappingProperties = $this->_generateEntityAssociationMappingProperties($metadata);
|
2010-03-19 07:19:15 +03:00
|
|
|
$stubMethods = $this->_generateEntityStubMethods ? $this->_generateEntityStubMethods($metadata) : null;
|
2010-03-19 00:38:42 +03:00
|
|
|
$lifecycleCallbackMethods = $this->_generateEntityLifecycleCallbackMethods($metadata);
|
|
|
|
|
|
|
|
$code = '';
|
|
|
|
if ($fieldMappingProperties) {
|
|
|
|
$code .= $fieldMappingProperties . "\n";
|
|
|
|
}
|
|
|
|
if ($associationMappingProperties) {
|
|
|
|
$code .= $associationMappingProperties . "\n";
|
|
|
|
}
|
|
|
|
if ($stubMethods) {
|
|
|
|
$code .= $stubMethods . "\n";
|
|
|
|
}
|
|
|
|
if ($lifecycleCallbackMethods) {
|
|
|
|
$code .= $lifecycleCallbackMethods . "\n";
|
|
|
|
}
|
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _hasProperty($property, ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
if ($this->_isNew) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2010-03-19 01:35:16 +03:00
|
|
|
return $this->_reflection->hasProperty($property);
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _hasMethod($method, ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
if ($this->_isNew) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2010-03-19 01:35:16 +03:00
|
|
|
return $this->_reflection->hasMethod($method);
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _hasNamespace(ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
return strpos($metadata->name, '\\') ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _extendsClass()
|
|
|
|
{
|
|
|
|
return $this->_classToExtend ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _getClassToExtend()
|
|
|
|
{
|
|
|
|
return $this->_classToExtend;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _getClassToExtendName()
|
|
|
|
{
|
|
|
|
$refl = new \ReflectionClass($this->_getClassToExtend());
|
|
|
|
return $refl->getShortName();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _getClassToExtendNamespace()
|
|
|
|
{
|
|
|
|
$refl = new \ReflectionClass($this->_getClassToExtend());
|
|
|
|
return $refl->getNamespaceName() ? $refl->getNamespaceName():$refl->getShortName();
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _getClassName(ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
if ($pos = strrpos($metadata->name, '\\')) {
|
|
|
|
return substr($metadata->name, $pos + 1, strlen($metadata->name));
|
|
|
|
} else {
|
|
|
|
return $metadata->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _getNamespace(ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
return substr($metadata->name, 0, strrpos($metadata->name, '\\'));
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _generateEntityDocBlock(ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
$lines = array();
|
|
|
|
$lines[] = '/**';
|
2010-03-20 01:38:45 +03:00
|
|
|
$lines[] = ' * '.$metadata->name;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($this->_generateAnnotations) {
|
|
|
|
$lines[] = ' *';
|
|
|
|
|
|
|
|
$methods = array(
|
|
|
|
'_generateTableAnnotation',
|
|
|
|
'_generateInheritanceAnnotation',
|
|
|
|
'_generateDiscriminatorColumnAnnotation',
|
|
|
|
'_generateDiscriminatorMapAnnotation'
|
|
|
|
);
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
foreach ($methods as $method) {
|
|
|
|
if ($code = $this->$method($metadata)) {
|
|
|
|
$lines[] = ' * ' . $code;
|
|
|
|
}
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($metadata->isMappedSuperclass) {
|
|
|
|
$lines[] = ' * @MappedSupperClass';
|
|
|
|
} else {
|
|
|
|
$lines[] = ' * @Entity';
|
|
|
|
}
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($metadata->customRepositoryClassName) {
|
|
|
|
$lines[count($lines) - 1] .= '(repositoryClass="' . $metadata->customRepositoryClassName . '")';
|
|
|
|
}
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
|
|
|
|
$lines[] = ' * @HasLifecycleCallbacks';
|
|
|
|
}
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
$lines[] = ' */';
|
|
|
|
|
|
|
|
return implode("\n", $lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateTableAnnotation($metadata)
|
|
|
|
{
|
|
|
|
$table = array();
|
2010-03-19 01:35:16 +03:00
|
|
|
if ($metadata->primaryTable['name']) {
|
|
|
|
$table[] = 'name="' . $metadata->primaryTable['name'] . '"';
|
|
|
|
}
|
2010-03-19 00:38:42 +03:00
|
|
|
|
|
|
|
if (isset($metadata->primaryTable['schema'])) {
|
|
|
|
$table[] = 'schema="' . $metadata->primaryTable['schema'] . '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
return '@Table(' . implode(', ', $table) . ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateInheritanceAnnotation($metadata)
|
|
|
|
{
|
|
|
|
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
|
|
|
|
return '@InheritanceType("'.$this->_getInheritanceTypeString($metadata->inheritanceType).'")';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateDiscriminatorColumnAnnotation($metadata)
|
|
|
|
{
|
|
|
|
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
|
|
|
|
$discrColumn = $metadata->discriminatorValue;
|
|
|
|
$columnDefinition = 'name="' . $discrColumn['name']
|
|
|
|
. '", type="' . $discrColumn['type']
|
|
|
|
. '", length=' . $discrColumn['length'];
|
|
|
|
|
|
|
|
return '@DiscriminatorColumn(' . $columnDefinition . ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateDiscriminatorMapAnnotation($metadata)
|
|
|
|
{
|
|
|
|
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
|
|
|
|
$inheritanceClassMap = array();
|
|
|
|
|
|
|
|
foreach ($metadata->discriminatorMap as $type => $class) {
|
|
|
|
$inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
return '@DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityStubMethods(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
$methods = array();
|
|
|
|
|
|
|
|
foreach ($metadata->fieldMappings as $fieldMapping) {
|
|
|
|
if ( ! isset($fieldMapping['id']) || ! $fieldMapping['id']) {
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'])) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'])) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($metadata->associationMappings as $associationMapping) {
|
|
|
|
if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToOneMapping) {
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
|
|
|
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\OneToManyMapping) {
|
|
|
|
if ($associationMapping->isOwningSide) {
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'set', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
|
|
|
} else {
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, 'Doctrine\Common\Collections\Collection')) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ($associationMapping instanceof \Doctrine\ORM\Mapping\ManyToManyMapping) {
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'add', $associationMapping->sourceFieldName, $associationMapping->targetEntityName)) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($code = $this->_generateEntityStubMethod($metadata, 'get', $associationMapping->sourceFieldName, 'Doctrine\Common\Collections\Collection')) {
|
2010-03-19 00:38:42 +03:00
|
|
|
$methods[] = $code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
return implode("\n\n", $methods);
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityLifecycleCallbackMethods(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
if (isset($metadata->lifecycleCallbacks) && $metadata->lifecycleCallbacks) {
|
|
|
|
$methods = array();
|
|
|
|
foreach ($metadata->lifecycleCallbacks as $name => $callbacks) {
|
|
|
|
foreach ($callbacks as $callback) {
|
|
|
|
if ($code = $this->_generateLifecycleCallbackMethod($name, $callback, $metadata)) {
|
|
|
|
$methods[] = $code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return implode('', $methods);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityAssociationMappingProperties(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
$lines = array();
|
|
|
|
foreach ($metadata->associationMappings as $associationMapping) {
|
|
|
|
if ($this->_hasProperty($associationMapping->sourceFieldName, $metadata)) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
$lines[] = $this->_generateAssociationMappingPropertyDocBlock($associationMapping, $metadata);
|
2010-03-19 00:38:42 +03:00
|
|
|
$lines[] = $this->_spaces . 'private $' . $associationMapping->sourceFieldName . ($associationMapping->isManyToMany() ? ' = array()' : null) . ";\n";
|
|
|
|
}
|
|
|
|
$code = implode("\n", $lines);
|
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateEntityFieldMappingProperties(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
$lines = array();
|
|
|
|
foreach ($metadata->fieldMappings as $fieldMapping) {
|
|
|
|
if ($this->_hasProperty($fieldMapping['fieldName'], $metadata)) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
$lines[] = $this->_generateFieldMappingPropertyDocBlock($fieldMapping, $metadata);
|
|
|
|
$lines[] = $this->_spaces . 'private $' . $fieldMapping['fieldName'] . (isset($fieldMapping['default']) ? ' = ' . var_export($fieldMapping['default'], true) : null) . ";\n";
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
$code = implode("\n", $lines);
|
|
|
|
return $code;
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
2010-03-20 01:38:45 +03:00
|
|
|
$methodName = $type . Inflector::classify($fieldName);
|
2010-03-19 00:38:42 +03:00
|
|
|
if ($this->_hasMethod($methodName, $metadata)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$var = sprintf('_%sMethodTemplate', $type);
|
|
|
|
$template = self::$$var;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$variableType = $typeHint ? $typeHint . ' ' : null;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$types = \Doctrine\DBAL\Types\Type::getTypesMap();
|
|
|
|
$methodTypeHint = $typeHint && ! isset($types[$typeHint]) ? $typeHint . ' ' : null;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$replacements = array(
|
|
|
|
'<description>' => ucfirst($type) . ' ' . $fieldName,
|
|
|
|
'<methodTypeHint>' => $methodTypeHint,
|
|
|
|
'<variableType>' => $variableType,
|
|
|
|
'<variableName>' => Inflector::camelize($fieldName),
|
|
|
|
'<methodName>' => $methodName,
|
|
|
|
'<fieldName>' => $fieldName
|
|
|
|
);
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$method = str_replace(
|
|
|
|
array_keys($replacements),
|
|
|
|
array_values($replacements),
|
|
|
|
$template
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->_prefixCodeWithSpaces($method);
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateLifecycleCallbackMethod($name, $methodName, $metadata)
|
|
|
|
{
|
|
|
|
if ($this->_hasMethod($methodName, $metadata)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$replacements = array(
|
|
|
|
'<name>' => $name,
|
|
|
|
'<methodName>' => $methodName,
|
|
|
|
);
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$method = str_replace(
|
|
|
|
array_keys($replacements),
|
|
|
|
array_values($replacements),
|
|
|
|
self::$_lifecycleCallbackMethodTemplate
|
|
|
|
);
|
|
|
|
return $this->_prefixCodeWithSpaces($method);
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private function _generateJoinColumnAnnotation(array $joinColumn)
|
|
|
|
{
|
|
|
|
$joinColumnAnnot = array();
|
|
|
|
if (isset($joinColumn['name'])) {
|
|
|
|
$joinColumnAnnot[] = 'name="' . $joinColumn['name'] . '"';
|
|
|
|
}
|
|
|
|
if (isset($joinColumn['referencedColumnName'])) {
|
|
|
|
$joinColumnAnnot[] = 'referencedColumnName="' . $joinColumn['referencedColumnName'] . '"';
|
|
|
|
}
|
|
|
|
if (isset($joinColumn['unique']) && $joinColumn['unique']) {
|
|
|
|
$joinColumnAnnot[] = 'unique=' . ($joinColumn['unique'] ? 'true' : 'false');
|
|
|
|
}
|
|
|
|
if (isset($joinColumn['nullable'])) {
|
|
|
|
$joinColumnAnnot[] = 'nullable=' . ($joinColumn['nullable'] ? 'true' : 'false');
|
|
|
|
}
|
|
|
|
if (isset($joinColumn['onDelete'])) {
|
|
|
|
$joinColumnAnnot[] = 'onDelete=' . ($joinColumn['onDelete'] ? 'true' : 'false');
|
|
|
|
}
|
|
|
|
if (isset($joinColumn['onUpdate'])) {
|
|
|
|
$joinColumnAnnot[] = 'onUpdate=' . ($joinColumn['onUpdate'] ? 'true' : 'false');
|
|
|
|
}
|
|
|
|
if (isset($joinColumn['columnDefinition'])) {
|
|
|
|
$joinColumnAnnot[] = 'columnDefinition="' . $joinColumn['columnDefinition'] . '"';
|
|
|
|
}
|
|
|
|
return '@JoinColumn(' . implode(', ', $joinColumnAnnot) . ')';
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _generateAssociationMappingPropertyDocBlock(AssociationMapping $associationMapping, ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
$lines = array();
|
|
|
|
$lines[] = $this->_spaces . '/**';
|
2010-03-20 01:38:45 +03:00
|
|
|
$lines[] = $this->_spaces . ' * @var ' . $associationMapping->targetEntityName;
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($this->_generateAnnotations) {
|
|
|
|
$lines[] = $this->_spaces . ' *';
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$e = explode('\\', get_class($associationMapping));
|
|
|
|
$type = str_replace('Mapping', '', end($e));
|
|
|
|
$typeOptions = array();
|
|
|
|
if (isset($associationMapping->targetEntityName)) {
|
|
|
|
$typeOptions[] = 'targetEntity="' . $associationMapping->targetEntityName . '"';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($associationMapping->mappedBy)) {
|
|
|
|
$typeOptions[] = 'mappedBy="' . $associationMapping->mappedBy . '"';
|
|
|
|
}
|
|
|
|
if ($associationMapping->hasCascades()) {
|
|
|
|
$cascades = array();
|
|
|
|
if ($associationMapping->isCascadePersist) $cascades[] = '"persist"';
|
|
|
|
if ($associationMapping->isCascadeRemove) $cascades[] = '"remove"';
|
|
|
|
if ($associationMapping->isCascadeDetach) $cascades[] = '"detach"';
|
|
|
|
if ($associationMapping->isCascadeMerge) $cascades[] = '"merge"';
|
|
|
|
if ($associationMapping->isCascadeRefresh) $cascades[] = '"refresh"';
|
|
|
|
$typeOptions[] = 'cascade={' . implode(',', $cascades) . '}';
|
|
|
|
}
|
|
|
|
if (isset($associationMapping->orphanRemoval) && $associationMapping->orphanRemoval) {
|
|
|
|
$typeOptions[] = 'orphanRemoval=' . ($associationMapping->orphanRemoval ? 'true' : 'false');
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$lines[] = $this->_spaces . ' * @' . $type . '(' . implode(', ', $typeOptions) . ')';
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($associationMapping->joinColumns) && $associationMapping->joinColumns) {
|
|
|
|
$lines[] = $this->_spaces . ' * @JoinColumns({';
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
$joinColumnsLines = array();
|
|
|
|
foreach ($associationMapping->joinColumns as $joinColumn) {
|
|
|
|
if ($joinColumnAnnot = $this->_generateJoinColumnAnnotation($joinColumn)) {
|
|
|
|
$joinColumnsLines[] = $this->_spaces . ' * ' . $joinColumnAnnot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$lines[] = implode(",\n", $joinColumnsLines);
|
|
|
|
$lines[] = $this->_spaces . ' * })';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($associationMapping->joinTable) && $associationMapping->joinTable) {
|
|
|
|
$joinTable = array();
|
|
|
|
$joinTable[] = 'name="' . $associationMapping->joinTable['name'] . '"';
|
|
|
|
if (isset($associationMapping->joinTable['schema'])) {
|
|
|
|
$joinTable[] = 'schema="' . $associationMapping->joinTable['schema'] . '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
$lines[] = $this->_spaces . ' * @JoinTable(' . implode(', ', $joinTable) . ',';
|
|
|
|
|
|
|
|
$lines[] = $this->_spaces . ' * joinColumns={';
|
|
|
|
foreach ($associationMapping->joinTable['joinColumns'] as $joinColumn) {
|
|
|
|
$lines[] = $this->_spaces . ' * ' . $this->_generateJoinColumnAnnotation($joinColumn);
|
|
|
|
}
|
|
|
|
$lines[] = $this->_spaces . ' * },';
|
|
|
|
|
|
|
|
$lines[] = $this->_spaces . ' * inverseJoinColumns={';
|
|
|
|
foreach ($associationMapping->joinTable['inverseJoinColumns'] as $joinColumn) {
|
|
|
|
$lines[] = $this->_spaces . ' * ' . $this->_generateJoinColumnAnnotation($joinColumn);
|
|
|
|
}
|
|
|
|
$lines[] = $this->_spaces . ' * }';
|
|
|
|
|
|
|
|
$lines[] = $this->_spaces . ' * )';
|
|
|
|
}
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($associationMapping->orderBy)) {
|
|
|
|
$lines[] = $this->_spaces . ' * @OrderBy({';
|
|
|
|
foreach ($associationMapping->orderBy as $name => $direction) {
|
|
|
|
$lines[] = $this->_spaces . ' * "' . $name . '"="' . $direction . '",';
|
|
|
|
}
|
|
|
|
$lines[count($lines) - 1] = substr($lines[count($lines) - 1], 0, strlen($lines[count($lines) - 1]) - 1);
|
|
|
|
$lines[] = $this->_spaces . ' * })';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$lines[] = $this->_spaces . ' */';
|
|
|
|
|
|
|
|
return implode("\n", $lines);
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _generateFieldMappingPropertyDocBlock(array $fieldMapping, ClassMetadataInfo $metadata)
|
2010-03-19 00:38:42 +03:00
|
|
|
{
|
|
|
|
$lines = array();
|
|
|
|
$lines[] = $this->_spaces . '/**';
|
2010-03-20 01:38:45 +03:00
|
|
|
$lines[] = $this->_spaces . ' * @var ' . $fieldMapping['type'] . ' $' . $fieldMapping['fieldName'];
|
2010-03-19 00:38:42 +03:00
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($this->_generateAnnotations) {
|
|
|
|
$lines[] = $this->_spaces . ' *';
|
|
|
|
|
|
|
|
$column = array();
|
|
|
|
if (isset($fieldMapping['columnName'])) {
|
|
|
|
$column[] = 'name="' . $fieldMapping['columnName'] . '"';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($fieldMapping['type'])) {
|
|
|
|
$column[] = 'type="' . $fieldMapping['type'] . '"';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($fieldMapping['length'])) {
|
|
|
|
$column[] = 'length=' . $fieldMapping['length'];
|
|
|
|
}
|
|
|
|
if (isset($fieldMapping['precision'])) {
|
|
|
|
$column[] = 'precision=' . $fieldMapping['precision'];
|
|
|
|
}
|
|
|
|
if (isset($fieldMapping['scale'])) {
|
|
|
|
$column[] = 'scale=' . $fieldMapping['scale'];
|
|
|
|
}
|
|
|
|
if (isset($fieldMapping['nullable'])) {
|
|
|
|
$column[] = 'nullable=' . var_export($fieldMapping['nullable'], true);
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if (isset($fieldMapping['columnDefinition'])) {
|
|
|
|
$column[] = 'columnDefinition="' . $fieldMapping['columnDefinition'] . '"';
|
|
|
|
}
|
|
|
|
if (isset($fieldMapping['options'])) {
|
|
|
|
$options = array();
|
|
|
|
foreach ($fieldMapping['options'] as $key => $value) {
|
|
|
|
$value = var_export($value, true);
|
|
|
|
$value = str_replace("'", '"', $value);
|
|
|
|
$options[] = ! is_numeric($key) ? $key . '=' . $value:$value;
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
if ($options) {
|
|
|
|
$column[] = 'options={' . implode(', ', $options) . '}';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
}
|
|
|
|
if (isset($fieldMapping['unique'])) {
|
|
|
|
$column[] = 'unique=' . var_export($fieldMapping['unique'], true);
|
|
|
|
}
|
|
|
|
$lines[] = $this->_spaces . ' * @Column(' . implode(', ', $column) . ')';
|
|
|
|
if (isset($fieldMapping['id']) && $fieldMapping['id']) {
|
|
|
|
$lines[] = $this->_spaces . ' * @Id';
|
|
|
|
if ($generatorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) {
|
|
|
|
$lines[] = $this->_spaces.' * @GeneratedValue(strategy="' . $generatorType . '")';
|
|
|
|
}
|
|
|
|
if ($metadata->sequenceGeneratorDefinition) {
|
|
|
|
$sequenceGenerator = array();
|
|
|
|
if (isset($metadata->sequenceGeneratorDefinition['sequenceName'])) {
|
|
|
|
$sequenceGenerator[] = 'sequenceName="' . $metadata->sequenceGeneratorDefinition['sequenceName'] . '"';
|
|
|
|
}
|
|
|
|
if (isset($metadata->sequenceGeneratorDefinition['allocationSize'])) {
|
|
|
|
$sequenceGenerator[] = 'allocationSize="' . $metadata->sequenceGeneratorDefinition['allocationSize'] . '"';
|
|
|
|
}
|
|
|
|
if (isset($metadata->sequenceGeneratorDefinition['initialValue'])) {
|
|
|
|
$sequenceGenerator[] = 'initialValue="' . $metadata->sequenceGeneratorDefinition['initialValue'] . '"';
|
|
|
|
}
|
|
|
|
$lines[] = $this->_spaces . ' * @SequenceGenerator(' . implode(', ', $sequenceGenerator) . ')';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
}
|
|
|
|
if (isset($fieldMapping['version']) && $fieldMapping['version']) {
|
|
|
|
$lines[] = $this->_spaces . ' * @Version';
|
2010-03-19 00:38:42 +03:00
|
|
|
}
|
|
|
|
}
|
2010-03-20 01:38:45 +03:00
|
|
|
|
2010-03-19 00:38:42 +03:00
|
|
|
$lines[] = $this->_spaces . ' */';
|
|
|
|
|
|
|
|
return implode("\n", $lines);
|
|
|
|
}
|
|
|
|
|
2010-03-20 01:38:45 +03:00
|
|
|
private function _prefixCodeWithSpaces($code, $num = 1)
|
|
|
|
{
|
|
|
|
$lines = explode("\n", $code);
|
|
|
|
foreach ($lines as $key => $value) {
|
|
|
|
$lines[$key] = str_repeat($this->_spaces, $num) . $lines[$key];
|
|
|
|
}
|
|
|
|
return implode("\n", $lines);
|
|
|
|
}
|
|
|
|
|
2010-03-19 00:38:42 +03:00
|
|
|
private function _getInheritanceTypeString($type)
|
|
|
|
{
|
|
|
|
switch ($type)
|
|
|
|
{
|
|
|
|
case ClassMetadataInfo::INHERITANCE_TYPE_NONE:
|
|
|
|
return 'NONE';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::INHERITANCE_TYPE_JOINED:
|
|
|
|
return 'JOINED';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE:
|
|
|
|
return 'SINGLE_TABLE';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS:
|
|
|
|
return 'PER_CLASS';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _getChangeTrackingPolicyString($policy)
|
|
|
|
{
|
|
|
|
switch ($policy)
|
|
|
|
{
|
|
|
|
case ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT:
|
|
|
|
return 'DEFERRED_IMPLICIT';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT:
|
|
|
|
return 'DEFERRED_EXPLICIT';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::CHANGETRACKING_NOTIFY:
|
|
|
|
return 'NOTIFY';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function _getIdGeneratorTypeString($type)
|
|
|
|
{
|
|
|
|
switch ($type)
|
|
|
|
{
|
|
|
|
case ClassMetadataInfo::GENERATOR_TYPE_AUTO:
|
|
|
|
return 'AUTO';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE:
|
|
|
|
return 'SEQUENCE';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::GENERATOR_TYPE_TABLE:
|
|
|
|
return 'TABLE';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ClassMetadataInfo::GENERATOR_TYPE_IDENTITY:
|
|
|
|
return 'IDENTITY';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|