[李景山php]每天TP5-20161228|thinkphp5-Console.php-5

來源:互聯網
上載者:User

標籤:thinkphp

    /**     * 設定預設命令     * @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 群號:414194301” 部落格,請務必保留此出處http://jingshanls.blog.51cto.com/3357095/1875646

[李景山php]每天TP5-20161228|thinkphp5-Console.php-5

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.