/**
* 设置默认命令
* @return Command[] An array of default Command instances
*/
protected function getDefaultCommands()
{// 获取默认命令
$defaultCommands = [];// 默认命令仓库
foreach (self::$defaultCommands as $classname) {
if (class_exists($classname) && is_subclass_of($classname, "think\\console\\Command")) {
$defaultCommands[] = new $classname();
}
}// 循环处理 数据
return $defaultCommands;// 返回 处理结果
}
// 太简单了
public static function addDefaultCommands(array $classnames)
{// 添加默认 命令
self::$defaultCommands = array_merge(self::$defaultCommands, $classnames);
}// 命令集 合并方案
/**
* 获取可能的建议
* @param array $abbrevs
* @return string
*/
private function getAbbreviationSuggestions($abbrevs)
{// 获取可能的建议
return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');
}// return 返回格式
/**
* 返回命名空间部分
* @param string $name 指令
* @param string $limit 部分的命名空间的最大数量
* @return string
*/
public function extractNamespace($name, $limit = null)
{// 获取 命名空间限制
$parts = explode(':', $name);// 分割
array_pop($parts);// 退出
return implode(':', null === $limit ? $parts : array_slice($parts, 0, $limit));
}// 返回命名空间部分
/**
* 查找可替代的建议
* @param string $name
* @param array|\Traversable $collection
* @return array
*/
private function findAlternatives($name, $collection)
{// 查找 可替代的建议
$threshold = 1e3;// 线程,还是?
$alternatives = [];// 仓库 方式
$collectionParts = [];// 仓库
foreach ($collection as $item) {
$collectionParts[$item] = explode(':', $item);
}// 很有意思的拆分
foreach (explode(':', $name) as $i => $subname) {// 拆分 子 名字
foreach ($collectionParts as $collectionName => $parts) {// 再次内部循环
$exists = isset($alternatives[$collectionName]);// 逻辑判读
if (!isset($parts[$i]) && $exists) {
$alternatives[$collectionName] += $threshold;
continue;
} elseif (!isset($parts[$i])) {
continue;
}
// 流程2
$lev = levenshtein($subname, $parts[$i]);
if ($lev <= strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
$alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
} elseif ($exists) {
$alternatives[$collectionName] += $threshold;
}
}
}
foreach ($collection as $item) {// 对参数进行判读
$lev = levenshtein($name, $item);
if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
$alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
}
}
$alternatives = array_filter($alternatives, function ($lev) use ($threshold) {
return $lev < 2 * $threshold;
});// 参数 过滤器
asort($alternatives);
return array_keys($alternatives);
}
/**
* 设置默认的指令
* @param string $commandName The Command name
*/
public function setDefaultCommand($commandName)
{
$this->defaultCommand = $commandName;
}// 默认返回
/**
* 返回所有的命名空间
* @param string $name
* @return array
*/
private function extractAllNamespaces($name)
{// 返回所有的命名空间
$parts = explode(':', $name, -1);
$namespaces = [];
foreach ($parts as $part) {
if (count($namespaces)) {
$namespaces[] = end($namespaces) . ':' . $part;
} else {
$namespaces[] = $part;
}
}// 遍历循环
return $namespaces;
}
}
[李景山php]每天TP5-20161228|thinkphp5-Console.php-5
最新推荐文章于 2024-03-22 10:54:08 发布