think\Console::extractNamespace PHP Method

extractNamespace() public method

返回命名空间部分
public extractNamespace ( string $name, string $limit = null ) : string
$name string 指令
$limit string 部分的命名空间的最大数量
return string
    public function extractNamespace($name, $limit = null)
    {
        $parts = explode(':', $name);
        array_pop($parts);
        return implode(':', null === $limit ? $parts : array_slice($parts, 0, $limit));
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @param array $commands
  * @return array
  */
 private function sortCommands(array $commands)
 {
     $namespacedCommands = [];
     foreach ($commands as $name => $command) {
         $key = $this->console->extractNamespace($name, 1);
         if (!$key) {
             $key = '_global';
         }
         $namespacedCommands[$key][$name] = $command;
     }
     ksort($namespacedCommands);
     foreach ($namespacedCommands as &$commandsSet) {
         ksort($commandsSet);
     }
     // unset reference to keep scope clear
     unset($commandsSet);
     return $namespacedCommands;
 }