You are here

public function Bundle::registerCommands in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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:

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\Bundle

Code

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