think\Console::all PHP Method

all() public method

获取所有的指令
public all ( string $namespace = null ) : Command[]
$namespace string 命名空间
return think\console\Command[]
    public function all($namespace = null)
    {
        if (null === $namespace) {
            return $this->commands;
        }
        $commands = [];
        foreach ($this->commands as $name => $command) {
            if ($this->extractNamespace($name, substr_count($namespace, ':') + 1) === $namespace) {
                $commands[$name] = $command;
            }
        }
        return $commands;
    }

Usage Example

Example #1
0
 private function inspectConsole()
 {
     $this->commands = [];
     $this->namespaces = [];
     $all = $this->console->all($this->namespace ? $this->console->findNamespace($this->namespace) : null);
     foreach ($this->sortCommands($all) as $namespace => $commands) {
         $names = [];
         /** @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] = ['id' => $namespace, 'commands' => $names];
     }
 }