PHP Класс yii\console\Controller

A console controller consists of one or several actions known as sub-commands. Users call a console command by specifying the corresponding route which identifies a controller action. The yii program is used when calling a console command, like the following: ~~~ yii [--param1=value1 --param2 ...] ~~~ where is a route to a controller action and the params will be populated as properties of a command. See Controller::options for details.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Controller
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$color whether to enable ANSI color in the output. If not set, ANSI color will only be enabled for terminals that support it.
$help whether to display help information about current command.
$interactive whether to run the command interactively.

Открытые методы

Метод Описание
ansiFormat ( string $string ) : string Formats a string with ANSI codes
bindActionParams ( Action $action, array $params ) : array Binds the parameters to the action.
confirm ( string $message, boolean $default = false ) : boolean Asks user to confirm by typing y or n.
getActionArgsHelp ( Action $action ) : array Returns the help information for the anonymous arguments for the action.
getActionHelp ( Action $action ) : string Returns the detailed help information for the specified action.
getActionHelpSummary ( Action $action ) : string Returns a one-line short summary describing the specified action.
getActionOptionsHelp ( Action $action ) : array Returns the help information for the options for the action.
getHelp ( ) : string Returns help information for this controller.
getHelpSummary ( ) : string Returns one-line short summary describing this controller.
getOptionValues ( string $actionID ) : array Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties.
getPassedOptionValues ( ) : array Returns the properties corresponding to the passed options
getPassedOptions ( ) : array Returns the names of valid options passed during execution.
isColorEnabled ( resource $stream = STDOUT ) : boolean Returns a value indicating whether ANSI color is enabled.
optionAliases ( ) : array Returns option alias names.
options ( string $actionID ) : string[] Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name.
prompt ( string $text, array $options = [] ) : string Prompts the user for input and validates it
runAction ( string $id, array $params = [] ) : integer Runs an action with the specified action ID and parameters.
select ( string $prompt, array $options = [] ) : string Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations.
stderr ( string $string ) : integer | boolean Prints a string to STDERR
stdout ( string $string ) : integer | boolean Prints a string to STDOUT

Защищенные методы

Метод Описание
getActionMethodReflection ( Action $action ) : ReflectionMethod
parseDocCommentDetail ( Reflector $reflection ) : string Returns full description from the docblock.
parseDocCommentSummary ( Reflector $reflection ) : string Returns the first line of docblock.
parseDocCommentTags ( Reflector $reflection ) : array Parses the comment block into tags.

Описание методов

ansiFormat() публичный Метод

You may pass additional parameters using the constants defined in [[\yii\helpers\Console]]. Example: echo $this->ansiFormat('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
public ansiFormat ( string $string ) : string
$string string the string to be formatted
Результат string

bindActionParams() публичный Метод

This method is invoked by [[Action]] when it begins to run with the given parameters. This method will first bind the parameters with the [[options()|options]] available to the action. It then validates the given arguments.
public bindActionParams ( Action $action, array $params ) : array
$action yii\base\Action the action to be bound with parameters
$params array the parameters to be bound to the action
Результат array the valid parameters that the action can run with.

confirm() публичный Метод

Asks user to confirm by typing y or n.
public confirm ( string $message, boolean $default = false ) : boolean
$message string to echo out before waiting for user input
$default boolean this value is returned if no selection is made.
Результат boolean whether user confirmed. Will return true if [[interactive]] is false.

getActionArgsHelp() публичный Метод

The returned value should be an array. The keys are the argument names, and the values are the corresponding help information. Each value must be an array of the following structure: - required: boolean, whether this argument is required. - type: string, the PHP type of this argument. - default: string, the default value of this argument - comment: string, the comment of this argument The default implementation will return the help information extracted from the doc-comment of the parameters corresponding to the action method.
public getActionArgsHelp ( Action $action ) : array
$action yii\base\Action
Результат array the help information of the action arguments

getActionHelp() публичный Метод

Returns the detailed help information for the specified action.
public getActionHelp ( Action $action ) : string
$action yii\base\Action action to get help for
Результат string the detailed help information for the specified action.

getActionHelpSummary() публичный Метод

Returns a one-line short summary describing the specified action.
public getActionHelpSummary ( Action $action ) : string
$action yii\base\Action action to get summary for
Результат string a one-line short summary describing the specified action.

getActionMethodReflection() защищенный Метод

protected getActionMethodReflection ( Action $action ) : ReflectionMethod
$action yii\base\Action
Результат ReflectionMethod

getActionOptionsHelp() публичный Метод

The returned value should be an array. The keys are the option names, and the values are the corresponding help information. Each value must be an array of the following structure: - type: string, the PHP type of this argument. - default: string, the default value of this argument - comment: string, the comment of this argument The default implementation will return the help information extracted from the doc-comment of the properties corresponding to the action options.
public getActionOptionsHelp ( Action $action ) : array
$action yii\base\Action
Результат array the help information of the action options

getHelp() публичный Метод

You may override this method to return customized help. The default implementation returns help information retrieved from the PHPDoc comment.
public getHelp ( ) : string
Результат string

getHelpSummary() публичный Метод

You may override this method to return customized summary. The default implementation returns first line from the PHPDoc comment.
public getHelpSummary ( ) : string
Результат string

getOptionValues() публичный Метод

Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties.
public getOptionValues ( string $actionID ) : array
$actionID string the action id of the current request
Результат array properties corresponding to the options for the action

getPassedOptionValues() публичный Метод

Returns the properties corresponding to the passed options
public getPassedOptionValues ( ) : array
Результат array the properties corresponding to the passed options

getPassedOptions() публичный Метод

Returns the names of valid options passed during execution.
public getPassedOptions ( ) : array
Результат array the names of the options passed during execution

isColorEnabled() публичный Метод

ANSI color is enabled only if [[color]] is set true or is not set and the terminal supports ANSI color.
public isColorEnabled ( resource $stream = STDOUT ) : boolean
$stream resource the stream to check.
Результат boolean Whether to enable ANSI style in output.

optionAliases() публичный Метод

Child classes may override this method to specify alias options.
См. также: options()
С версии: 2.0.8
public optionAliases ( ) : array
Результат array the options alias names valid for the action where the keys is alias name for option and value is option name.

options() публичный Метод

Child classes may override this method to specify possible options. Note that the values setting via options are not available until [[beforeAction()]] is being called.
public options ( string $actionID ) : string[]
$actionID string the action id of the current request
Результат string[] the names of the options valid for the action

parseDocCommentDetail() защищенный Метод

Returns full description from the docblock.
protected parseDocCommentDetail ( Reflector $reflection ) : string
$reflection Reflector
Результат string

parseDocCommentSummary() защищенный Метод

Returns the first line of docblock.
protected parseDocCommentSummary ( Reflector $reflection ) : string
$reflection Reflector
Результат string

parseDocCommentTags() защищенный Метод

Parses the comment block into tags.
protected parseDocCommentTags ( Reflector $reflection ) : array
$reflection Reflector the comment block
Результат array the parsed tags

prompt() публичный Метод

Prompts the user for input and validates it
public prompt ( string $text, array $options = [] ) : string
$text string prompt string
$options array the options to validate the input: - required: whether it is required or not - default: default value if no input is inserted by the user - pattern: regular expression pattern to validate user input - validator: a callable function to validate input. The function must accept two parameters: - $input: the user input to validate - $error: the error value passed by reference if validation failed. An example of how to use the prompt method with a validator function. ```php $code = $this->prompt('Enter 4-Chars-Pin', ['required' => true, 'validator' => function($input, &$error) { if (strlen($input) !== 4) { $error = 'The Pin must be exactly 4 chars!'; return false; } return true; }); ```
Результат string the user input

runAction() публичный Метод

If the action ID is empty, the method will use [[defaultAction]].
См. также: createAction
public runAction ( string $id, array $params = [] ) : integer
$id string the ID of the action to be executed.
$params array the parameters (name-value pairs) to be passed to the action.
Результат integer the status of the action execution. 0 means normal, other values mean abnormal.

select() публичный Метод

Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations.
public select ( string $prompt, array $options = [] ) : string
$prompt string the prompt message
$options array Key-value array of options to choose from
Результат string An option character the user chose

stderr() публичный Метод

You may optionally format the string with ANSI codes by passing additional parameters using the constants defined in [[\yii\helpers\Console]]. Example: $this->stderr('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
public stderr ( string $string ) : integer | boolean
$string string the string to print
Результат integer | boolean Number of bytes printed or false on error

stdout() публичный Метод

You may optionally format the string with ANSI codes by passing additional parameters using the constants defined in [[\yii\helpers\Console]]. Example: $this->stdout('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
public stdout ( string $string ) : integer | boolean
$string string the string to print
Результат integer | boolean Number of bytes printed or false on error

Описание свойств

$color публичное свойство

whether to enable ANSI color in the output. If not set, ANSI color will only be enabled for terminals that support it.
public $color

$help публичное свойство

whether to display help information about current command.
С версии: 2.0.10
public $help

$interactive публичное свойство

whether to run the command interactively.
public $interactive