diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 5410c08b4..f417ee0f9 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -24,7 +24,8 @@ namespace Doctrine\ORM\Tools\Console\Command; use Symfony\Components\Console\Input\InputArgument, Symfony\Components\Console\Input\InputOption, Symfony\Components\Console, - Doctrine\ORM\Tools\Console\MetadataFilter; + Doctrine\ORM\Tools\Console\MetadataFilter, + Doctrine\ORM\Tools\EntityRepositoryGenerator; /** * Command to generate repository classes for mapping information. @@ -40,23 +41,6 @@ use Symfony\Components\Console\Input\InputArgument, */ class GenerateRepositoriesCommand extends Console\Command\Command { - protected static $_template = -'; - -use Doctrine\ORM\EntityRepository; - -/** - * - * - * This class was generated by the Doctrine ORM. Add your own custom - * repository methods below. - */ -class extends EntityRepository -{ -}'; - /** * @see Console\Command\Command */ @@ -105,6 +89,7 @@ EOT if (count($metadatas)) { $numRepositories = 0; + $generator = new EntityRepositoryGenerator(); foreach ($metadatas as $metadata) { if ($metadata->customRepositoryClassName) { @@ -112,7 +97,7 @@ EOT sprintf('Processing repository "%s"', $metadata->customRepositoryClassName) . PHP_EOL ); - $this->_writeRepositoryClass($metadata, $destPath); + $generator->writeEntityRepositoryClass($metadata->customRepositoryClassName, $destPath); $numRepositories++; } @@ -128,33 +113,4 @@ EOT $output->write('No Metadata Classes to process.' . PHP_EOL); } } - - protected function _generateRepositoryClass($metadata) - { - fullClassName = $metadata->customRepositoryClassName; - $namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\')); - $className = substr($fullClassName, strrpos($fullClassName, '\\') + 1, strlen($fullClassName)); - - $variables = array( - '' => $namespace, - '' => $className - ); - $code = str_replace(array_keys($variables), array_values($variables), self::$_template); - return $code; - } - - protected function _writeRepositoryClass($metadata, $destPath) - { - $code = $this->_generateRepositoryClass($metadata); - - $path = $destPath . DIRECTORY_SEPARATOR - . str_replace('\\', \DIRECTORY_SEPARATOR, $metadata->customRepositoryClassName) . '.php'; - $dir = dirname($path); - - if ( ! is_dir($dir)) { - mkdir($dir, 0777, true); - } - - file_put_contents($path, $code); - } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php new file mode 100644 index 000000000..82c18035e --- /dev/null +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -0,0 +1,81 @@ +. + */ + +namespace Doctrine\ORM\Tools; + +/** + * Class to generate entity repository classes + * + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Benjamin Eberlei + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel + */ +class EntityRepositoryGenerator +{ + protected static $_template = +'; + +use Doctrine\ORM\EntityRepository; + +/** + * + * + * This class was generated by the Doctrine ORM. Add your own custom + * repository methods below. + */ +class extends EntityRepository +{ +}'; + + public function generateEntityRepositoryClass($fullClassName) + { + $namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\')); + $className = substr($fullClassName, strrpos($fullClassName, '\\') + 1, strlen($fullClassName)); + + $variables = array( + '' => $namespace, + '' => $className + ); + return str_replace(array_keys($variables), array_values($variables), self::$_template); + } + + public function writeEntityRepositoryClass($fullClassName, $outputDirectory) + { + $code = $this->generateEntityRepositoryClass($fullClassName); + + $path = $outputDirectory . DIRECTORY_SEPARATOR + . str_replace('\\', \DIRECTORY_SEPARATOR, $fullClassName) . '.php'; + $dir = dirname($path); + + if ( ! is_dir($dir)) { + mkdir($dir, 0777, true); + } + + file_put_contents($path, $code); + } +} \ No newline at end of file