[Framework] Fixed command registration magic to work when commands have sub-namespaces.

This commit is contained in:
Kris Wallsmith 2010-07-15 04:31:22 -07:00
parent 92130c3da1
commit 6462814483
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());
}