毎日laravel-20160718|Command-2

10155 ワード

    // 2016-04-15
    /**
     * Call another console command.
     *
     * @param  string  $command
     * @param  array   $arguments
     * @return int
     */
    public function call($command, array $arguments = [])
    {
        $instance = $this->getApplication()->find($command);// get the find($command)
        // a instance
        $arguments['command'] = $command;// save the command to the $arguments.

        return $instance->run(new ArrayInput($arguments), $this->output);// $instance->run
    }// Call another console command
   // a ArrayInput $this->output
   // ArrayInput($argument),$this->output;
   // ArrayInput($argument), change the command array to a new array.

    /**
     * Call another console command silently.
     *
     * @param  string  $command
     * @param  array   $arguments
     * @return int
     */
    public function callSilent($command, array $arguments = [])//call Silent function
    {
        $instance = $this->getApplication()->find($command);// get command instance

        $arguments['command'] = $command;// $arguments

        return $instance->run(new ArrayInput($arguments), new NullOutput);// no outPut
    }// call another console command silently

    /**
     * Get the value of a command argument.
     *
     * @param  string  $key
     * @return string|array
     */
    public function argument($key = null)
    {
        if (is_null($key)) {
            return $this->input->getArguments();
        }// all argument to send back

        return $this->input->getArgument($key);// get you  want value by you key
    }// Get the value of a command argument.

    /**
     * Get the value of a command option.
     *
     * @param  string  $key
     * @return string|array
     */
    public function option($key = null)
    {
        if (is_null($key)) {
            return $this->input->getOptions();
        }// $this->input->getOptions();

        return $this->input->getOption($key);// get the getOption by key
    }// Get the value of a command option

    /**
     * Confirm a question with the user.
     *
     * @param  string  $question
     * @param  bool    $default
     * @return bool
     */
    public function confirm($question, $default = false)
    {// use api function to check the question
        return $this->output->confirm($question, $default);
    }// Confirm a question with the user.

    /**
     * Prompt the user for input.
     *
     * @param  string  $question
     * @param  string  $default
     * @return string
     */
    public function ask($question, $default = null)
    {
        return $this->output->ask($question, $default);
    }// Prompt the user for input.
   // use the

    /**
     * Prompt the user for input with auto completion.
     *
     * @param  string  $question
     * @param  array   $choices
     * @param  string  $default
     * @return string
     */
    public function anticipate($question, array $choices, $default = null)
    {
        return $this->askWithCompletion($question, $choices, $default);// askWithCompletion
    }// Prompt the user for input with auto completion

    /**
     * Prompt the user for input with auto completion.
     *
     * @param  string  $question
     * @param  array   $choices
     * @param  string  $default
     * @return string
     */
    public function askWithCompletion($question, array $choices, $default = null)
    {
        $question = new Question($question, $default);// get a question

        $question->setAutocompleterValues($choices);//api function

        return $this->output->askQuestion($question);//api function
    }//Prompt the user for input with auto completion

    /**
     * Prompt the user for input but hide the answer from the console.
     *
     * @param  string  $question
     * @param  bool    $fallback
     * @return string
     */
    public function secret($question, $fallback = true)
    {
        $question = new Question($question);

        $question->setHidden(true)->setHiddenFallback($fallback);

        return $this->output->askQuestion($question);
    }//Prompt the user for input but hide the answer from the console.

    /**
     * Give the user a single choice from an array of answers.
     *
     * @param  string  $question
     * @param  array   $choices
     * @param  string  $default
     * @param  mixed   $attempts
     * @param  bool    $multiple
     * @return string
     */
    public function choice($question, array $choices, $default = null, $attempts = null, $multiple = null)
    {
        $question = new ChoiceQuestion($question, $choices, $default);

        $question->setMaxAttempts($attempts)->setMultiselect($multiple);

        return $this->output->askQuestion($question);
    }// Give the user a single choice from an array of answers.

    /**
     * Format input to textual table.
     *
     * @param  array   $headers
     * @param  \Illuminate\Contracts\Support\Arrayable|array  $rows
     * @param  string  $style
     * @return void
     */
    public function table(array $headers, $rows, $style = 'default')
    {
        $table = new Table($this->output);// get the Table instance

        if ($rows instanceof Arrayable) {
            $rows = $rows->toArray();
        }//

        $table->setHeaders($headers)->setRows($rows)->setStyle($style)->render();
    }// Format input to textual table.
   // use a class mode

    /**
     * Write a string as information output.
     *
     * @param  string  $string
     * @param  null|int|string  $verbosity
     * @return void
     */
    public function info($string, $verbosity = null)
    {
        $this->line($string, 'info', $verbosity);//line the info
    }// Write a string as information output.

    /**
     * Write a string as standard output.
     *
     * @param  string  $string
     * @param  string  $style
     * @param  null|int|string  $verbosity
     * @return void
     */
    public function line($string, $style = null, $verbosity = null)
    {
        $styled = $style ? "$string$style>" : $string;// set the string

        $this->output->writeln($styled, $this->parseVerbosity($verbosity));// use a writeln
    }// Write a string as standard output
   // writeln


    /**
     * Write a string as comment output.
     *
     * @param  string  $string
     * @param  null|int|string  $verbosity
     * @return void
     */
    public function comment($string, $verbosity = null)
    {
        $this->line($string, 'comment', $verbosity);// line comment
       // Write a string as comment output.
    }// Write a string as comment output.

    /**
     * Write a string as question output.
     *
     * @param  string  $string
     * @param  null|int|string  $verbosity
     * @return void
     */
    public function question($string, $verbosity = null)
    {
        $this->line($string, 'question', $verbosity);// line()
    }// Write a string as question output.

    /**
     * Write a string as error output.
     *
     * @param  string  $string
     * @param  null|int|string  $verbosity
     * @return void
     */
    public function error($string, $verbosity = null)
    {
        $this->line($string, 'error', $verbosity);// line() write a line
    }// Write a string as error output.

    /**
     * Write a string as warning output.
     *
     * @param  string  $string
     * @param  null|int|string  $verbosity
     * @return void
     */
    public function warn($string, $verbosity = null)
    {
        if (! $this->output->getFormatter()->hasStyle('warning')) {
            $style = new OutputFormatterStyle('yellow');// new OutputFormatterStyle

            $this->output->getFormatter()->setStyle('warning', $style);// has the warning
        }

        $this->line($string, 'warning', $verbosity);
    }//Write a string as warning output.

    /**
     * Get the verbosity level in terms of Symfony's OutputInterface level.
     *
     * @param  string|int  $level
     * @return int
     */
    protected function parseVerbosity($level = null)
    {
        if (isset($this->verbosityMap[$level])) {
            $level = $this->verbosityMap[$level];// $level
        } elseif (! is_int($level)) {
            $level = $this->verbosity;// the verbosity
        }

        return $level;
    }//Get the verbosity level terms of Symfony's OutputInterface level.

    /**
     * Set the verbosity level.
     *
     * @param string|int $level
     * @return void
     */
    protected function setVerbosity($level)
    {
        $this->verbosity = $this->parseVerbosity($level);// verbosity
    }// Set the verbosity level.

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return [];// a empty array();
    }// Get the console command arguments.

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return [];// a empty array();
    }// Get the console command options.

    /**
     * Get the output implementation.
     *
     * @return \Symfony\Component\Console\Output\OutputInterface
     */
    public function getOutput()
    {
        return $this->output;// a empty array();
    }//Get the output implementation.

    /**
     * Get the Laravel application instance.
     *
     * @return \Illuminate\Contracts\Foundation\Application
     */
    public function getLaravel()
    {
        return $this->laravel;
    }//Get the laravel application instance.
   // return the laravel

    /**
     * Set the Laravel application instance.
     *
     * @param  \Illuminate\Contracts\Container\Container  $laravel
     * @return void
     */
    public function setLaravel($laravel)
    {
        $this->laravel = $laravel;//Set the laravel
    }// Set the laravel application instance.
}