PHP Class yii\console\Application

Application extends from Application by providing functionalities that are specific to console requests. In particular, it deals with console requests through a command-based approach: - A console application consists of one or several possible user commands; - Each user command is implemented as a class extending Controller; - User specifies which command to run on the command line; - The command processes the user request with the specified parameters. The command classes should be under the namespace specified by [[controllerNamespace]]. Their naming should follow the same naming convention as controllers. For example, the help command is implemented using the HelpController class. To run the console application, enter the following on the command line: ~~~ yii [--param1=value1 --param2 ...] ~~~ where refers to a controller route in the form of ModuleID/ControllerID/ActionID (e.g. sitemap/create), and param1, param2 refers to a set of named parameters that will be used to initialize the controller action (e.g. --since=0 specifies a since parameter whose value is 0 and a corresponding $since parameter is passed to the action method). A help command is provided by default, which lists available commands and shows their usage. To use this command, simply type: ~~~ yii help ~~~
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends yii\base\Application
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство Type Description
$controller the currently active controller instance
$defaultRoute the default route of this application. Defaults to 'help', meaning the help command.
$enableCoreCommands whether to enable the commands provided by the core framework. Defaults to true.

Méthodes publiques

Méthode Description
__construct ( $config = [] )
coreCommands ( ) : array Returns the configuration of the built-in commands.
coreComponents ( )
getErrorHandler ( ) : yii\console\ErrorHandler Returns the error handler component.
getRequest ( ) : yii\console\Request Returns the request component.
getResponse ( ) : Response Returns the response component.
handleRequest ( yii\console\Request $request ) : Response Handles the specified request.
init ( ) Initialize the application.
runAction ( string $route, array $params = [] ) : integer | Response Runs a controller action specified by a route.

Méthodes protégées

Méthode Description
loadConfig ( array $config ) : array Loads the configuration.

Method Details

__construct() public méthode

public __construct ( $config = [] )

coreCommands() public méthode

Returns the configuration of the built-in commands.
public coreCommands ( ) : array
Résultat array the configuration of the built-in commands.

coreComponents() public méthode

public coreComponents ( )

getErrorHandler() public méthode

Returns the error handler component.
public getErrorHandler ( ) : yii\console\ErrorHandler
Résultat yii\console\ErrorHandler the error handler application component.

getRequest() public méthode

Returns the request component.
public getRequest ( ) : yii\console\Request
Résultat yii\console\Request the request component.

getResponse() public méthode

Returns the response component.
public getResponse ( ) : Response
Résultat Response the response component.

handleRequest() public méthode

Handles the specified request.
public handleRequest ( yii\console\Request $request ) : Response
$request yii\console\Request the request to be handled
Résultat Response the resulting response

init() public méthode

Initialize the application.
public init ( )

loadConfig() protected méthode

This method will check if the command line option [[OPTION_APPCONFIG]] is specified. If so, the corresponding file will be loaded as the application configuration. Otherwise, the configuration provided as the parameter will be returned back.
protected loadConfig ( array $config ) : array
$config array the configuration provided in the constructor.
Résultat array the actual configuration to be used by the application.

runAction() public méthode

This method parses the specified route and creates the corresponding child module(s), controller and action instances. It then calls [[Controller::runAction()]] to run the action with the given parameters. If the route is empty, the method will use [[defaultRoute]]. For example, to run public function actionTest($a, $b) assuming that the controller has options the following code should be used: php \Yii::$app->runAction('controller/test', ['option' => 'value', $a, $b]);
public runAction ( string $route, array $params = [] ) : integer | Response
$route string the route that specifies the action.
$params array the parameters to be passed to the action
Résultat integer | Response the result of the action. This can be either an exit code or Response object. Exit code 0 means normal, and other values mean abnormal. Exit code of `null` is treaded as `0` as well.

Property Details

$controller public_oe property

the currently active controller instance
public $controller

$defaultRoute public_oe property

the default route of this application. Defaults to 'help', meaning the help command.
public $defaultRoute

$enableCoreCommands public_oe property

whether to enable the commands provided by the core framework. Defaults to true.
public $enableCoreCommands