[Li Jingshan php] every day tp5-20161225|thinkphp5-console.php-2

Source: Internet
Author: User
Tags sprintf

/** *  execution Instructions  *  @param  Input   $input  *  @param  output $ output *  @return  int */public function dorun (input  $input,  Output   $output) {//  real   run   function start     if  (true ===  $input Hasparameteroption (['--version ',  '-V ')])  {         $output- >writeln ($this->getlongversion ());//  write out the version information         return  0;//  back  0    }//  If there is a   version      $name  =   $this->getcommandname ($input);//  get command   name     if  (true ===   $input->hasparameteroption (['--help ',  '-h '))  {//  if it is help information          if  (! $name)  {//  clear    linux  near             &nBSP; $name   =  ' help ';// help              $input  = new input ([' Help ']);//  back to information          } else {             $this- >wantHelps = true;//  set the information you want to help   to 1        }     }    if  (! $name)  {//  If the corresponding command is not obtained           $name   =  $this->defaultcommand;//  Set the default command           $input  = new input ([$this->defaultcommand]);//  Enter information as default command     }     $command  =  $this->find ($name);//  Find command   According to   name &NBSP;, first name is an index   primary key  id     $exitCode  =  $this Doruncommand ($command,  $input,  $output);//  execution   command   with   input   with output     return  $exitCode;//   Returns the result after execution}/** *  setting input parameter definition  *  @param  InputDefinition  $definition  */public  function setdefinition (inputdefinition  $definition) {     $this definition =  $definition;}   Set input parameter definition/** *  get input parameter definition  *  @return  InputDefinition The  Inputdefinition instance */public function getdefinition () {    return   $this->definition;}   Get input   parameters   define/** * gets the help message. *  @return   String a help message. */public function gethelp () {     return  $this->getlongversion ();}   Get help information   is   get version information/** *  catch exception  *  @param  bool  $boolean  *   @api  */public function setcatcheXceptions ($boolean) {     $this->catchexceptions =  (bool) $boolean;}   Set   Whether   catch exception, Force    convert   Some   data/** *  automatically exit  *  @param   bool  $boolean  *  @api  */public function setautoexit ($boolean) {      $this->autoexit =  (bool) $boolean;}   Auto Exit/** *  get name  *  @return  string */public function getname () {     return  $this->name;}   Return name/** *  set name  *  @param  string  $name  */public function  SetName ($name) {     $this->name =  $name;}   Set name/** *  get version  *  @return  string *  @api  */public function  getversion () {    return  $this->version;}   Set version/** *  set version  *  @param  string  $version  */public function&nbSp;setversion ($version) {     $this->version =  $version;} Set version/** *  get the full version number  *  @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> ';//  info   display   Control}//  get version number/** *  register a directive  *   @param  string  $name  *  @return  command */public function register ($name) {    return  $this->add (New command ($name));}   Registration   Instruction/** *  add Directive  *  @param  command[]  $commands  */public function addcommands (array  $commands) {     foreach  ($commands  as  $command)  {         $this- >add ($command);    }}//  add   Directive/** *  add a directive  *  @param   command  $command  *  @return  command */public function add (command $ command) {     $command->setconsole ($this);//  setup commands   consoles      if  (! $command->isenabled ())  {         $command Setconsole (null);         return null;    }//   Allow design, Setup     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));    }//  get default   parameters   definitions       $this->commands[$command->getname ()] =  $command;//  commands   Settings      foreach  ($command->getaliases ()  as  $alias)  {          $this->commands[$alias] =  $command;    }//  loop   Settings   Aliases     return  $command;//  return   data}/** *  get instructions  * @ param string  $name   directive name  *  @return  Command *  @throws  \ Invalidargumentexception */public function get ($name) {//  access   directives      if  (!isset ($this->commands[$name])  {        throw  new \invalidargumentexception (sprintF (' the command  "%s"  does not exist. ',  $name));    }//  Throw   Settings   exceptions      $command  =  $this->commands[$name];//  Setup command      if  ($this->wanthelps)  {         $this- >wantHelps = false;        /**  @var  helpcommand   $helpCommand  */         $helpCommand  =  $this Get (' help ');         $helpCommand->setcommand ($command);         return  $helpCommand;    }//  some   help commands     return  $command;//  return command}


This article is from the "Focus on PHP Group number: 414194301" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1873737

[Li Jingshan php] every day tp5-20161225|thinkphp5-console.php-2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.