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
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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