From 66efd65e6476c953572e5e2249cf22469ef49a0b Mon Sep 17 00:00:00 2001 From: twinh Date: Thu, 11 Oct 2012 06:01:55 -0700 Subject: [PATCH 1/2] fixed empty namespace in generated code when repository class do not have namespace --- .../ORM/Tools/EntityRepositoryGenerator.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index e696abcdb..508730b9c 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -35,7 +35,7 @@ class EntityRepositoryGenerator protected static $_template = '; + use Doctrine\ORM\EntityRepository; @@ -52,16 +52,28 @@ class extends EntityRepository public function generateEntityRepositoryClass($fullClassName) { - $namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\')); $className = substr($fullClassName, strrpos($fullClassName, '\\') + 1, strlen($fullClassName)); $variables = array( - '' => $namespace, + '' => $this->generateEntityRepositoryNamespace($fullClassName), '' => $className ); return str_replace(array_keys($variables), array_values($variables), self::$_template); } - + + /** + * Generate the namespace statement, if class do not have namespace, return empty string instead + * + * @param string $fullClassName The full repository class name + * @return string $namespace + */ + private function generateEntityRepositoryNamespace($fullClassName) + { + $namespace = substr($fullClassName, 0, strrpos($fullClassName, '\\')); + + return $namespace ? 'namespace ' . $namespace . ';' : ''; + } + public function writeEntityRepositoryClass($fullClassName, $outputDirectory) { $code = $this->generateEntityRepositoryClass($fullClassName); From 8cc24f4cf2e6ada91220c90620643834a0c28a8a Mon Sep 17 00:00:00 2001 From: twinh Date: Thu, 11 Oct 2012 06:04:03 -0700 Subject: [PATCH 2/2] removed blanks --- lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php index 508730b9c..94bb5354f 100644 --- a/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityRepositoryGenerator.php @@ -60,7 +60,7 @@ class extends EntityRepository ); return str_replace(array_keys($variables), array_values($variables), self::$_template); } - + /** * Generate the namespace statement, if class do not have namespace, return empty string instead *