| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | <?phpnamespace app\command;use think\console\Input;use think\console\Output;use think\facade\Log;/** * 命令行基类,提供基本功能,继承的子类重写main方法即可 * Class Base * @package app\command */class Base extends \think\console\Command{    protected $input; //输入变量    protected $output;//输出引用    /**     * 输出方法     * @param $obj     * @param string $type     */    protected function writeln($obj,$type="info"){        $msg=print_r($obj,true);        Log::record($msg,$type);        $this->output->writeln("[".$type."]".$msg);    }    /**     * 命令行核心方法,不要重写     * @param Input $input     * @param Output $output     * @return int|void|null     */    protected function execute(Input $input, Output $output)    {        $this->input=$input;        $this->output=$output;        $this->main();    }    /**     * 命令行主程序,继承后重写此方法,将业务写在此方法中     */    protected function main(){    }}
 |