PHP Класс 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 ~~~
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends yii\base\Application
Показать файл Открыть проект Примеры использования класса

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

Свойство Тип Описание
$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.

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

Метод Описание
__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.

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

Метод Описание
loadConfig ( array $config ) : array Loads the configuration.

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

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

public __construct ( $config = [] )

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

Returns the configuration of the built-in commands.
public coreCommands ( ) : array
Результат array the configuration of the built-in commands.

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

public coreComponents ( )

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

Returns the error handler component.
public getErrorHandler ( ) : yii\console\ErrorHandler
Результат yii\console\ErrorHandler the error handler application component.

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

Returns the request component.
public getRequest ( ) : yii\console\Request
Результат yii\console\Request the request component.

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

Returns the response component.
public getResponse ( ) : Response
Результат Response the response component.

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

Handles the specified request.
public handleRequest ( yii\console\Request $request ) : Response
$request yii\console\Request the request to be handled
Результат Response the resulting response

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

Initialize the application.
public init ( )

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

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.
Результат array the actual configuration to be used by the application.

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

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
Результат 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.

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

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

the currently active controller instance
public $controller

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

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

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

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