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.
This commit is contained in:
Fabien Potencier 2010-07-16 16:24:16 +02:00
commit 826e61561a
2 changed files with 6 additions and 6 deletions

View File

@ -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());
}

View File

@ -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());
}