updated bootstrap.php

This commit is contained in:
Fabien Potencier 2010-07-13 21:15:32 +02:00
parent b8f29f18c0
commit 92130c3da1

View File

@ -5,6 +5,7 @@ namespace Symfony\Framework\Bundle;
use Symfony\Components\DependencyInjection\ContainerInterface; use Symfony\Components\DependencyInjection\ContainerInterface;
use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Components\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Components\Console\Application; use Symfony\Components\Console\Application;
use Symfony\Components\Finder\Finder;
@ -74,25 +75,18 @@ abstract class Bundle implements BundleInterface
public function registerCommands(Application $application) public function registerCommands(Application $application)
{ {
foreach ($application->getKernel()->getBundleDirs() as $dir) { if (!is_dir($dir = $this->getPath().'/Command')) {
$bundleBase = dirname(str_replace('\\', '/', get_class($this))); return;
$commandDir = $dir.'/'.basename($bundleBase).'/Command'; }
if (!is_dir($commandDir)) {
continue;
}
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($commandDir), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { $finder = new Finder();
if ($file->isDir() || substr($file, -4) !== '.php') { $finder->files()->name('*Command.php')->in($dir);
continue;
}
$class = str_replace('/', '\\', $bundleBase).'\\Command\\'.str_replace(realpath($commandDir).'/', '', basename(realpath($file), '.php')); $prefix = $this->namespacePrefix.'\\'.$this->name.'\\Command\\';
foreach ($finder as $file) {
$r = new \ReflectionClass($class); $r = new \ReflectionClass($prefix.basename($file, '.php'));
if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) {
if ($r->isSubclassOf('Symfony\\Components\\Console\\Command\\Command') && !$r->isAbstract()) { $application->addCommand($r->newInstance());
$application->addCommand(new $class());
}
} }
} }
} }