Ver Fonte

Add a namespace separator for console commands in `Command` sub-directories.

Fixes a bug in `Bundle::registerCommands` with console commands in sub-directories of `Command`. `MyBundle\Command\FooCommand` worked great, but with `MyBundle\Command\Bar\BazCommand` Bundle would try to register `MyBundle\CommandBar\BazCommand` instead.
Justin Hileman há 14 anos atrás
pai
commit
b8c531e1fc
1 ficheiros alterados com 5 adições e 1 exclusões
  1. 5 1
      src/Symfony/Component/HttpKernel/Bundle/Bundle.php

+ 5 - 1
src/Symfony/Component/HttpKernel/Bundle/Bundle.php

@@ -149,7 +149,11 @@ abstract class Bundle extends ContainerAware implements BundleInterface
 
         $prefix = $this->getNamespace().'\\Command';
         foreach ($finder as $file) {
-            $r = new \ReflectionClass($prefix.strtr($file->getRelativePath(), '/', '\\').'\\'.$file->getBasename('.php'));
+            $ns = $prefix;
+            if ($relativePath = $file->getRelativePath()) {
+                $ns .= '\\'.strtr($relativePath, '/', '\\');
+            }
+            $r = new \ReflectionClass($ns.'\\'.$file->getBasename('.php'));
             if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract()) {
                 $application->add($r->newInstance());
             }