[李景山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->getLongVersion());// 写出版本信息

        return 0;// 返回 0
    }// 如果有 版本

    $name = $this->getCommandName($input);// 获取命令 名字

    if (true === $input->hasParameterOption([‘--help‘, ‘-h‘])) {// 如果是帮助信息
        if (!$name) {// 明显 跟 linux 靠近了
            $name  = ‘help‘;// help
            $input = new Input([‘help‘]);// 返回帮助信息
        } else {
            $this->wantHelps = true;// 把想要帮助的信息 设置为1
        }
    }

    if (!$name) {// 如果没有获取到相应的命令
        $name  = $this->defaultCommand;// 设置默认的命令
        $input = new Input([$this->defaultCommand]);// 输入信息为默认命令
    }

    $command = $this->find($name);// 查找命令 根据 名字 ,名字,其实就是个索引 主键 id

    $exitCode = $this->doRunCommand($command, $input, $output);// 执行 命令 带着 输入 跟输出

    return $exitCode;// 返回执行后的结果
}

/**
 * 设置输入参数定义
 * @param InputDefinition $definition
 */
public function setDefinition(InputDefinition $definition)
{
    $this->definition = $definition;
}// 设置输入参数定义

/**
 * 获取输入参数定义
 * @return InputDefinition The InputDefinition instance
 */
public function getDefinition()
{
    return $this->definition;
}// 获取输入 参数 定义

/**
 * Gets the help message.
 * @return string A help message.
 */
public function getHelp()
{
    return $this->getLongVersion();
}// 获取帮助信息 就是 获取版本信息

/**
 * 是否捕获异常
 * @param bool $boolean
 * @api
 */
public function setCatchExceptions($boolean)
{
    $this->catchExceptions = (bool)$boolean;
}// 设置 是否 捕获异常,强制  转换 一些 数据

/**
 * 是否自动退出
 * @param bool $boolean
 * @api
 */
public function setAutoExit($boolean)
{
    $this->autoExit = (bool)$boolean;
}// 自动退出

/**
 * 获取名称
 * @return string
 */
public function getName()
{
    return $this->name;
}// 返回名字

/**
 * 设置名称
 * @param string $name
 */
public function setName($name)
{
    $this->name = $name;
}// 设置名字

/**
 * 获取版本
 * @return string
 * @api
 */
public function getVersion()
{
    return $this->version;
}// 设置版本

/**
 * 设置版本
 * @param string $version
 */
public function setVersion($version)
{
    $this->version = $version;
}//设置版本

/**
 * 获取完整的版本号
 * @return string
 */
public function getLongVersion()
{
    if (‘UNKNOWN‘ !== $this->getName() && ‘UNKNOWN‘ !== $this->getVersion()) {
        return sprintf(‘<info>%s</info> version <comment>%s</comment>‘, $this->getName(), $this->getVersion());
    }

    return ‘<info>Console Tool</info>‘;// 信息 显示 控制
}// 获取版本号

/**
 * 注册一个指令
 * @param string $name
 * @return Command
 */
public function register($name)
{
    return $this->add(new Command($name));
}// 注册 指令

/**
 * 添加指令
 * @param Command[] $commands
 */
public function addCommands(array $commands)
{
    foreach ($commands as $command) {
        $this->add($command);
    }
}// 添加 指令

/**
 * 添加一个指令
 * @param Command $command
 * @return Command
 */
public function add(Command $command)
{
    $command->setConsole($this);// 设置命令 控制台

    if (!$command->isEnabled()) {
        $command->setConsole(null);
        return null;
    }// 允许设计,进行设置

    if (null === $command->getDefinition()) {
        throw new \LogicException(sprintf(‘Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.‘, get_class($command)));
    }// 获取默认 参数 定义

    $this->commands[$command->getName()] = $command;// 命令 设置

    foreach ($command->getAliases() as $alias) {
        $this->commands[$alias] = $command;
    }// 循环 设置 别名

    return $command;// 返回 数据
}

/**
 * 获取指令
 * @param string $name 指令名称
 * @return Command
 * @throws \InvalidArgumentException
 */
public function get($name)
{// 获取 指令
    if (!isset($this->commands[$name])) {
        throw new \InvalidArgumentException(sprintf(‘The command "%s" does not exist.‘, $name));
    }// 抛出 设置 异常

    $command = $this->commands[$name];// 设置命令

    if ($this->wantHelps) {
        $this->wantHelps = false;

        /** @var HelpCommand $helpCommand */
        $helpCommand = $this->get(‘help‘);
        $helpCommand->setCommand($command);

        return $helpCommand;
    }// 一些 帮助的命令

    return $command;// 返回命令
}
时间: 2024-08-01 19:09:48

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

[李景山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) {  

安装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