You are here

public function Application::findNamespace in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Application.php \Symfony\Component\Console\Application::findNamespace()

Finds a registered namespace by a name or an abbreviation.

Parameters

string $namespace A namespace or abbreviation to search for:

Return value

string A registered namespace

Throws

\InvalidArgumentException When namespace is incorrect or ambiguous

1 call to Application::findNamespace()
Application::find in vendor/symfony/console/Application.php
Finds a command by name or alias.

File

vendor/symfony/console/Application.php, line 446

Class

Application
An Application is the container for a collection of commands.

Namespace

Symfony\Component\Console

Code

public function findNamespace($namespace) {
  $allNamespaces = $this
    ->getNamespaces();
  $expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
    return preg_quote($matches[1]) . '[^:]*';
  }, $namespace);
  $namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
  if (empty($namespaces)) {
    $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
    if ($alternatives = $this
      ->findAlternatives($namespace, $allNamespaces)) {
      if (1 == count($alternatives)) {
        $message .= "\n\nDid you mean this?\n    ";
      }
      else {
        $message .= "\n\nDid you mean one of these?\n    ";
      }
      $message .= implode("\n    ", $alternatives);
    }
    throw new \InvalidArgumentException($message);
  }
  $exact = in_array($namespace, $namespaces, true);
  if (count($namespaces) > 1 && !$exact) {
    throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this
      ->getAbbreviationSuggestions(array_values($namespaces))));
  }
  return $exact ? $namespace : reset($namespaces);
}