Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Application.php

function Application::findNamespace

Finds a registered namespace by a name or an abbreviation.

Throws

NamespaceNotFoundException When namespace is incorrect or ambiguous

2 calls to Application::findNamespace()
Application::doRun in vendor/symfony/console/Application.php
Runs the current application.
Application::find in vendor/symfony/console/Application.php
Finds a command by name or alias.

File

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

Class

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

Namespace

Symfony\Component\Console

Code

public function findNamespace(string $namespace) : string {
    $allNamespaces = $this->getNamespaces();
    $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))) . '[^:]*';
    $namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
    if (!$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 NamespaceNotFoundException($message, $alternatives);
    }
    $exact = \in_array($namespace, $namespaces, true);
    if (\count($namespaces) > 1 && !$exact) {
        throw new NamespaceNotFoundException(\sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s.", $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces));
    }
    return $exact ? $namespace : reset($namespaces);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal