每天laravel-20160717|Command-1


namespace Illuminate\Console;

use Illuminate\Contracts\Support\Arrayable;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
// more namespace
class Command extends SymfonyCommand
{
    /**
     * The Laravel application instance.
     *
     * @var \Illuminate\Contracts\Foundation\Application
     */
    protected $laravel;// the big or base  instance.

    /**
     * The input interface implementation.
     *
     * @var \Symfony\Component\Console\Input\InputInterface
     */
    protected $input;// The input interface implementation.

    /**
     * The output interface implementation.
     *
     * @var \Illuminate\Console\OutputStyle
     */
    protected $output;// The output interface implementation.

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature;// The name and signature of the console command ,like a token

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name;// command name,like a key

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description;// command description

    /**
     * The default verbosity of output commands. // the detail about the output commands.
     * verbosity == detail
     * @var int
     */
    protected $verbosity = OutputInterface::VERBOSITY_NORMAL;// this is "32"

    /**
     * The mapping between human readable verbosity levels and Symfony's OutputInterface.
     *
     * @var array
     */
    protected $verbosityMap = [
        'v'      => OutputInterface::VERBOSITY_VERBOSE,
        'vv'     => OutputInterface::VERBOSITY_VERY_VERBOSE,
        'vvv'    => OutputInterface::VERBOSITY_DEBUG,
        'quiet'  => OutputInterface::VERBOSITY_QUIET,
        'normal' => OutputInterface::VERBOSITY_NORMAL,
    ];// a array to change the flag to a human can read flag

    /**
     * Create a new console command instance.
     *
     * @return void
     */
    public function __construct()
    {
        // We will go ahead and set the name, description, and parameters on console
        // commands just to make things a little easier on the developer. This is
        // so they don't have to all be manually specified in the constructors.
        if (isset($this->signature)) {
            $this->configureUsingFluentDefinition();
        } else {
            parent::__construct($this->name);
        }// two way , one is configureUsingFluentDefinition
        // anther use father __construct

        $this->setDescription($this->description);// Set Description

        if (! isset($this->signature)) {
            $this->specifyParameters();// set the specify Parameters.
        }
    }// create a new console command instance
    // we will go ahead and set the name , description, and parameters on console commands to make a little easier on the developer.
    // This is so they don't have to all be manually specified in the constructors.

    /**
     * Configure the console command using a fluent definition.
     *
     * @return void
     */
    protected function configureUsingFluentDefinition()
    {
        list($name, $arguments, $options) = Parser::parse($this->signature);// set the parser::parse();

        parent::__construct($name);// use father __construct(); with a variable

        foreach ($arguments as $argument) {
            $this->getDefinition()->addArgument($argument);
        }// this is a addArgument ($argument)
        // set the argument

        foreach ($options as $option) {
            $this->getDefinition()->addOption($option);
        }// set the option
    }// configure the console command using a definition

    /**
     * Specify the arguments and options on the command.
     *
     * @return void
     */
    protected function specifyParameters()// register arguments and options
    {
        // We will loop through all of the arguments and options for the command and
        // set them all on the base command instance. This specifies what can get
        // passed into these commands as "parameters" to control the execution.
        foreach ($this->getArguments() as $arguments) {
            call_user_func_array([$this, 'addArgument'], $arguments);
        }// call the argument function to add the argments

        foreach ($this->getOptions() as $options) {
            call_user_func_array([$this, 'addOption'], $options);
        }// call the addOption function to add the options
    }// send the right arguments and options  to the command.
    // we will loop through all of the arguments and options for the command and set them all on the base command instance.
    // This specifies what can get passed into these commands as "parameters" to control the execution

    /**
     * Run the console command.
     *
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
     * @return int
     */
    public function run(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;// get input

        $this->output = new OutputStyle($input, $output);// get output

        return parent::run($input, $output);// use parent::run();
    }// Run the console command.

    /**
     * Execute the console command.
     *
     * @param  \Symfony\Component\Console\Input\InputInterface  $input
     * @param  \Symfony\Component\Console\Output\OutputInterface  $output
     * @return mixed
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $method = method_exists($this, 'handle') ? 'handle' : 'fire';// check the way to start,

        return $this->laravel->call([$this, $method]);// never use the arguments
    }// a normal call the function, be ley mysql execute,
    // execute the console command.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值