Fixing generate-repositories command so it works again after migration to Symfony console
This commit is contained in:
parent
146b22a1a5
commit
32a81f09d1
@ -40,12 +40,12 @@ use Symfony\Components\Console\Input\InputArgument,
|
|||||||
*/
|
*/
|
||||||
class GenerateRepositoriesCommand extends Console\Command\Command
|
class GenerateRepositoriesCommand extends Console\Command\Command
|
||||||
{
|
{
|
||||||
private static $_template =
|
protected static $_template =
|
||||||
'<?php
|
'<?php
|
||||||
|
|
||||||
namespace <namespace>;
|
namespace <namespace>;
|
||||||
|
|
||||||
use \Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <className>
|
* <className>
|
||||||
@ -103,7 +103,7 @@ EOT
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( count($metadatas)) {
|
if (count($metadatas)) {
|
||||||
$numRepositories = 0;
|
$numRepositories = 0;
|
||||||
|
|
||||||
foreach ($metadatas as $metadata) {
|
foreach ($metadatas as $metadata) {
|
||||||
@ -112,7 +112,7 @@ EOT
|
|||||||
sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName) . PHP_EOL
|
sprintf('Processing repository "<info>%s</info>"', $metadata->customRepositoryClassName) . PHP_EOL
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->_generateRepositoryClass($metadata, $destPath);
|
$this->_writeRepositoryClass($metadata, $destPath);
|
||||||
|
|
||||||
$numRepositories++;
|
$numRepositories++;
|
||||||
}
|
}
|
||||||
@ -129,9 +129,23 @@ EOT
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _generateRepositoryClass($metadata, $destPath)
|
protected function _generateRepositoryClass($metadata)
|
||||||
{
|
{
|
||||||
$code = $this->_generateRepositoryClass($metadata->customRepositoryClassName);
|
fullClassName = $metadata->customRepositoryClassName;
|
||||||
|
$namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\'));
|
||||||
|
$className = substr($fullClassName, strrpos($fullClassName, '\\') + 1, strlen($fullClassName));
|
||||||
|
|
||||||
|
$variables = array(
|
||||||
|
'<namespace>' => $namespace,
|
||||||
|
'<className>' => $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
|
$path = $destPath . DIRECTORY_SEPARATOR
|
||||||
. str_replace('\\', \DIRECTORY_SEPARATOR, $metadata->customRepositoryClassName) . '.php';
|
. str_replace('\\', \DIRECTORY_SEPARATOR, $metadata->customRepositoryClassName) . '.php';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user