Bladeren bron

Merge commit 'kriswallsmith/register-commands-with-subnamespaces'

* commit 'kriswallsmith/register-commands-with-subnamespaces':
  [Framework] Fixed command registration magic to work when commands have sub-namespaces.
Fabien Potencier 15 jaren geleden
bovenliggende
commit
826e61561a
2 gewijzigde bestanden met toevoegingen van 6 en 6 verwijderingen
  1. 3 3
      src/Symfony/Framework/Bundle/Bundle.php
  2. 3 3
      src/Symfony/Framework/bootstrap.php

+ 3 - 3
src/Symfony/Framework/Bundle/Bundle.php

@@ -122,16 +122,16 @@ abstract class Bundle implements BundleInterface
      */
     public function registerCommands(Application $application)
     {
-        if (!is_dir($dir = $this->getPath().'/Command')) {
+        if (!$dir = realpath($this->getPath().'/Command')) {
             return;
         }
 
         $finder = new Finder();
         $finder->files()->name('*Command.php')->in($dir);
 
-        $prefix = $this->namespacePrefix.'\\'.$this->name.'\\Command\\';
+        $prefix = $this->namespacePrefix.'\\'.$this->name.'\\Command';
         foreach ($finder as $file) {
-            $r = new \ReflectionClass($prefix.basename($file, '.php'));
+            $r = new \ReflectionClass($prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.basename($file, '.php'));
             if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) {
                 $application->addCommand($r->newInstance());
             }

+ 3 - 3
src/Symfony/Framework/bootstrap.php

@@ -75,16 +75,16 @@ abstract class Bundle implements BundleInterface
     
     public function registerCommands(Application $application)
     {
-        if (!is_dir($dir = $this->getPath().'/Command')) {
+        if (!$dir = realpath($this->getPath().'/Command')) {
             return;
         }
 
         $finder = new Finder();
         $finder->files()->name('*Command.php')->in($dir);
 
-        $prefix = $this->namespacePrefix.'\\'.$this->name.'\\Command\\';
+        $prefix = $this->namespacePrefix.'\\'.$this->name.'\\Command';
         foreach ($finder as $file) {
-            $r = new \ReflectionClass($prefix.basename($file, '.php'));
+            $r = new \ReflectionClass($prefix.strtr($file->getPath(), array($dir => '', '/' => '\\')).'\\'.basename($file, '.php'));
             if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) {
                 $application->addCommand($r->newInstance());
             }