Finds and registers Commands.
Override this method if your bundle commands do not follow the conventions:
Application $application An Application instance:
public function registerCommands(Application $application) {
if (!($dir = realpath($this
->getPath() . '/Command'))) {
return;
}
$finder = new Finder();
$finder
->files()
->name('*Command.php')
->in($dir);
$prefix = $this
->getNamespace() . '\\Command';
foreach ($finder as $file) {
$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());
}
}
}