Symfony\Component\Console\Application::findNamespace PHP Метод

findNamespace() публичный Метод

Finds a registered namespace by a name or an abbreviation.
public findNamespace ( string $namespace ) : string
$namespace string A namespace or abbreviation to search for
Результат string A registered namespace
    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 CommandNotFoundException($message, $alternatives);
        }
        $exact = in_array($namespace, $namespaces, true);
        if (count($namespaces) > 1 && !$exact) {
            throw new CommandNotFoundException(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);
    }

Usage Example

 private function inspectApplication()
 {
     $this->commands = array();
     $this->namespaces = array();
     $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
     foreach ($this->sortCommands($all) as $namespace => $commands) {
         $names = array();
         /** @var Command $command */
         foreach ($commands as $name => $command) {
             if (!$command->getName()) {
                 continue;
             }
             if ($command->getName() === $name) {
                 $this->commands[$name] = $command;
             } else {
                 $this->aliases[$name] = $command;
             }
             $names[] = $name;
         }
         $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
     }
 }
All Usage Examples Of Symfony\Component\Console\Application::findNamespace