public function 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

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Bundle/Bundle.php, line 173

Class

Bundle
An implementation of BundleInterface that adds a few conventions for DependencyInjection extensions and Console commands.

Namespace

Symfony\Component\HttpKernel\Bundle

Code

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