public function Bundle::registerCommands in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-kernel/Bundle/Bundle.php \Symfony\Component\HttpKernel\Bundle\Bundle::registerCommands()
Finds and registers Commands.
Override this method if your bundle commands do not follow the conventions:
- Commands are in the 'Command' sub-directory
- Commands extend Symfony\Component\Console\Command\Command
Parameters
Application $application An Application instance:
File
- vendor/
symfony/ http-kernel/ Bundle/ Bundle.php, line 163
Class
- Bundle
- An implementation of BundleInterface that adds a few conventions for DependencyInjection extensions and Console commands.
Namespace
Symfony\Component\HttpKernel\BundleCode
public function registerCommands(Application $application) {
if (!is_dir($dir = $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, '/', '\\');
}
$class = $ns . '\\' . $file
->getBasename('.php');
if ($this->container) {
$alias = 'console.command.' . strtolower(str_replace('\\', '_', $class));
if ($this->container
->has($alias)) {
continue;
}
}
$r = new \ReflectionClass($class);
if ($r
->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r
->isAbstract() && !$r
->getConstructor()
->getNumberOfRequiredParameters()) {
$application
->add($r
->newInstance());
}
}
}