[李景山php]每天TP5-20161226|thinkphp5-Console.php-3

    /**
     * 某个指令是否存在
     * @param string $name 指令名称
     * @return bool
     */
    public function has($name)
    {
        return isset($this->commands[$name]);
    }// 判读是否拥有

    /**
     * 获取所有的命名空间
     * @return array
     */
    public function getNamespaces()
    {
        $namespaces = [];
        foreach ($this->commands as $command) {
            $namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));

            foreach ($command->getAliases() as $alias) {
                $namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
            }
        }

        return array_values(array_unique(array_filter($namespaces)));
    }// 命名空间大清洗, 过滤 唯一 返回值

    /**
     * 查找注册命名空间中的名称或缩写。
     * @param string $namespace
     * @return string
     * @throws \InvalidArgumentException
     */
    public function findNamespace($namespace)
    {// 查找注册命名空间中的名称或缩写
        $allNamespaces = $this->getNamespaces();// 获取 命名空间
        $expr          = preg_replace_callback(‘{([^:]+|)}‘, function ($matches) {
            return preg_quote($matches[1]) . ‘[^:]*‘;
        }, $namespace);// preg_replace_callback
        $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)) {// 找到 对应的 findAlter natives
                if (1 == count($alternatives)) {// 若干 count ==1
                    $message .= "\n\nDid you mean this?\n    ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n    ";
                }// 设置信息

                $message .= implode("\n    ", $alternatives); // 获取信息
            }

            throw new \InvalidArgumentException($message);// 抛出异常
        }

        $exact = in_array($namespace, $namespaces, true);// 在 数组中
        if (count($namespaces) > 1 && !$exact) {
            throw new \InvalidArgumentException(sprintf(‘The namespace "%s" is ambiguous (%s).‘, $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
        }// count($namespaces)

        return $exact ? $namespace : reset($namespaces);// 返回命名空间
    }

    /**
     * 查找指令
     * @param string $name 名称或者别名
     * @return Command
     * @throws \InvalidArgumentException
     */
    public function find($name)
    {// 简单的查找命名
        $allCommands = array_keys($this->commands);// 获取 key 数据
        $expr        = preg_replace_callback(‘{([^:]+|)}‘, function ($matches) {
            return preg_quote($matches[1]) . ‘[^:]*‘;
        }, $name);// 正则 回调 替换
        $commands    = preg_grep(‘{^‘ . $expr . ‘}‘, $allCommands);// 正则搜索 数据

        if (empty($commands) || count(preg_grep(‘{^‘ . $expr . ‘$}‘, $commands)) < 1) {
            if (false !== $pos = strrpos($name, ‘:‘)) {// 不为空
                $this->findNamespace(substr($name, 0, $pos));// 查找命名空间
            }//命令数据为空,获取 扶着的 数据为空

            $message = sprintf(‘Command "%s" is not defined.‘, $name);// 格式化 输出 信息

            if ($alternatives = $this->findAlternatives($name, $allCommands)) {
                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 \InvalidArgumentException($message);
        }// 抛出 参数 异常

        if (count($commands) > 1) {
            $commandList = $this->commands;
            $commands    = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
                $commandName = $commandList[$nameOrAlias]->getName();

                return $commandName === $nameOrAlias || !in_array($commandName, $commands);
            });
        }// 计算 命令行

        $exact = in_array($name, $commands, true);
        if (count($commands) > 1 && !$exact) {
            $suggestions = $this->getAbbreviationSuggestions(array_values($commands));

            throw new \InvalidArgumentException(sprintf(‘Command "%s" is ambiguous (%s).‘, $name, $suggestions));
        }// 如果 大于1

        return $this->get($exact ? $name : reset($commands));// 返回获取到的信息
    }
时间: 2024-08-04 15:15:54

[李景山php]每天TP5-20161226|thinkphp5-Console.php-3的相关文章

[李景山php]每天TP5-20161224|thinkphp5-Console.php-1

namespace think; use think\console\Command;// 控制台 命令 use think\console\command\Help as HelpCommand; // 帮助命令 use think\console\Input;// 输入 use think\console\input\Argument as InputArgument;// 输入参数 use think\console\input\Definition as InputDefinition;

[李景山php]每天TP5-20161221|thinkphp5-jump.php

<?php /**  * 用法:  * load_trait('controller/Jump');  * class index  * {  *     use \traits\controller\Jump;  *     public function index(){  *         $this->error();  *         $this->redirect();  *     }  * }  */ namespace traits\controller; use

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

    /**      * 设置默认命令      * @return Command[] An array of default Command instances      */     protected function getDefaultCommands()     {// 获取默认命令         $defaultCommands = [];// 默认命令仓库         foreach (self::$defaultCommands as $classname) {  

[李景山php]每天TP5-20161225|thinkphp5-Console.php-2

/**  * 执行指令  * @param Input  $input  * @param Output $output  * @return int  */ public function doRun(Input $input, Output $output) {// 真正 运行 函数开始     if (true === $input->hasParameterOption(['--version', '-V'])) {         $output->writeln($this->

安装TP5(thinkphp5)Composer

1.下载 composer.phar (http:\\www.cnblogs.com/JANCHAN/7735882.html),把composer.phar放入php中(例如php-5.4.45) 再建一个composer.bat放在php中(放在同级的文件夹中)---在里面写    @php "%~dp0composer.phar" %* 2.去网站根目录中的  配置  php.ini 改openssl.dll和fileinfo.dll去掉分号(按ctrl+F搜索) 3.写环境变量

[李景山php]每天laravel-20161103|CompilerEngine.php-2

    /**      * Handle a view exception.      *      * @param  \Exception  $e      * @param  int  $obLevel      * @return void      *      * @throws $e      */     protected function handleViewException(Exception $e, $obLevel)     {         $e = new E

[李景山php]每天laravel-20161104|Engine.php

<?php namespace Illuminate\View\Engines; abstract class Engine {     /**      * The view that was last to be rendered.      *      * @var string      */     protected $lastRendered;//The view that was last to be rendered.     /**      * Get the last 

[李景山php]每天laravel-20161105|EngineInterface.php

<?php namespace Illuminate\View\Engines; interface EngineInterface {     /**      * Get the evaluated contents of the view.      *      * @param  string  $path      * @param  array   $data      * @return string      */     public function get($path, 

[李景山php]每天laravel-20161106|EngineResolver.php

<?php namespace Illuminate\View\Engines; use Closure; use InvalidArgumentException; class EngineResolver {// engineResolver     /**      * The array of engine resolvers.      *      * @var array      */     protected $resolvers = [];// The array of e

[李景山php]每天laravel-20161107|PhpEngine.php

<?php namespace Illuminate\View\Engines; use Exception; use Throwable; use Symfony\Component\Debug\Exception\FatalThrowableError; class PhpEngine implements EngineInterface {// PhpEngine implements EngineInterface     /**      * Get the evaluated con