1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Merge pull request #61 from stof/EntityGenerator_3

Updated the EntityGenerator to be compatible with Common 3.0.x
This commit is contained in:
Benjamin Eberlei 2011-06-11 01:13:05 -07:00
commit 9945296472

View File

@ -91,6 +91,8 @@ class EntityGenerator
<namespace> <namespace>
use Doctrine\ORM\Mapping as ORM;
<entityAnnotation> <entityAnnotation>
<entityClassName> <entityClassName>
{ {
@ -146,11 +148,18 @@ public function <methodName>()
} }
'; ';
public function __construct()
{
if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0-DEV', '>=')) {
$this->_annotationsPrefix = 'ORM\\';
}
}
/** /**
* Generate and write entity classes for the given array of ClassMetadataInfo instances * Generate and write entity classes for the given array of ClassMetadataInfo instances
* *
* @param array $metadatas * @param array $metadatas
* @param string $outputDirectory * @param string $outputDirectory
* @return void * @return void
*/ */
public function generate(array $metadatas, $outputDirectory) public function generate(array $metadatas, $outputDirectory)
@ -164,7 +173,7 @@ public function <methodName>()
* Generated and write entity class to disk for the given ClassMetadataInfo instance * Generated and write entity class to disk for the given ClassMetadataInfo instance
* *
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $metadata
* @param string $outputDirectory * @param string $outputDirectory
* @return void * @return void
*/ */
public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory) public function writeEntityClass(ClassMetadataInfo $metadata, $outputDirectory)
@ -201,7 +210,7 @@ public function <methodName>()
/** /**
* Generate a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance * Generate a PHP5 Doctrine 2 entity class from the given ClassMetadataInfo instance
* *
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $metadata
* @return string $code * @return string $code
*/ */
public function generateEntityClass(ClassMetadataInfo $metadata) public function generateEntityClass(ClassMetadataInfo $metadata)
@ -227,8 +236,8 @@ public function <methodName>()
/** /**
* Generate the updated code for the given ClassMetadataInfo and entity at path * Generate the updated code for the given ClassMetadataInfo and entity at path
* *
* @param ClassMetadataInfo $metadata * @param ClassMetadataInfo $metadata
* @param string $path * @param string $path
* @return string $code; * @return string $code;
*/ */
public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path) public function generateUpdatedEntityClass(ClassMetadataInfo $metadata, $path)
@ -245,7 +254,7 @@ public function <methodName>()
/** /**
* Set the number of spaces the exported class should have * Set the number of spaces the exported class should have
* *
* @param integer $numSpaces * @param integer $numSpaces
* @return void * @return void
*/ */
public function setNumSpaces($numSpaces) public function setNumSpaces($numSpaces)
@ -257,7 +266,7 @@ public function <methodName>()
/** /**
* Set the extension to use when writing php files to disk * Set the extension to use when writing php files to disk
* *
* @param string $extension * @param string $extension
* @return void * @return void
*/ */
public function setExtension($extension) public function setExtension($extension)
@ -278,7 +287,7 @@ public function <methodName>()
/** /**
* Set whether or not to generate annotations for the entity * Set whether or not to generate annotations for the entity
* *
* @param bool $bool * @param bool $bool
* @return void * @return void
*/ */
public function setGenerateAnnotations($bool) public function setGenerateAnnotations($bool)
@ -293,13 +302,16 @@ public function <methodName>()
*/ */
public function setAnnotationPrefix($prefix) public function setAnnotationPrefix($prefix)
{ {
if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0-DEV', '>=')) {
return;
}
$this->_annotationsPrefix = $prefix; $this->_annotationsPrefix = $prefix;
} }
/** /**
* Set whether or not to try and update the entity if it already exists * Set whether or not to try and update the entity if it already exists
* *
* @param bool $bool * @param bool $bool
* @return void * @return void
*/ */
public function setUpdateEntityIfExists($bool) public function setUpdateEntityIfExists($bool)
@ -407,7 +419,7 @@ public function <methodName>()
$tokens = token_get_all($src); $tokens = token_get_all($src);
$lastSeenNamespace = ""; $lastSeenNamespace = "";
$lastSeenClass = false; $lastSeenClass = false;
$inNamespace = false; $inNamespace = false;
$inClass = false; $inClass = false;
for ($i = 0; $i < count($tokens); $i++) { for ($i = 0; $i < count($tokens); $i++) {
@ -808,7 +820,7 @@ public function <methodName>()
if ($associationMapping['isCascadeMerge']) $cascades[] = '"merge"'; if ($associationMapping['isCascadeMerge']) $cascades[] = '"merge"';
if ($associationMapping['isCascadeRefresh']) $cascades[] = '"refresh"'; if ($associationMapping['isCascadeRefresh']) $cascades[] = '"refresh"';
$typeOptions[] = 'cascade={' . implode(',', $cascades) . '}'; $typeOptions[] = 'cascade={' . implode(',', $cascades) . '}';
} }
if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval']) { if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval']) {
@ -862,7 +874,7 @@ public function <methodName>()
$lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'OrderBy({'; $lines[] = $this->_spaces . ' * @' . $this->_annotationsPrefix . 'OrderBy({';
foreach ($associationMapping['orderBy'] as $name => $direction) { foreach ($associationMapping['orderBy'] as $name => $direction) {
$lines[] = $this->_spaces . ' * "' . $name . '"="' . $direction . '",'; $lines[] = $this->_spaces . ' * "' . $name . '"="' . $direction . '",';
} }
$lines[count($lines) - 1] = substr($lines[count($lines) - 1], 0, strlen($lines[count($lines) - 1]) - 1); $lines[count($lines) - 1] = substr($lines[count($lines) - 1], 0, strlen($lines[count($lines) - 1]) - 1);