PHP Class yii\base\Application

For more details and usage information on Application, see the guide article on applications.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends Module
Mostra file Open project: yiisoft/yii2 Class Usage Examples

Public Properties

Property Type Description
$bootstrap list of components that should be run during the application [[bootstrap()|bootstrapping process]]. Each component may be specified in one of the following formats: - an application component ID as specified via [[components]]. - a module ID as specified via [[modules]]. - a class name. - a configuration array. During the bootstrapping process, each component will be instantiated. If the component class implements BootstrapInterface, its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called.
$charset the charset currently used for the application.
$controller the currently active controller instance
$controllerNamespace the namespace that controller classes are located in. This namespace will be used to load controller classes by prepending it to the controller class name. The default namespace is app\controllers. Please refer to the guide about class autoloading for more details.
$extensions list of installed Yii extensions. Each array element represents a single extension with the following structure: php [ 'name' => 'extension name', 'version' => 'version number', 'bootstrap' => 'BootstrapClassName', // optional, may also be a configuration array 'alias' => [ '@alias1' => 'to/path1', '@alias2' => 'to/path2', ], ] The "bootstrap" class listed above will be instantiated during the application [[bootstrap()|bootstrapping process]]. If the class implements BootstrapInterface, its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called. If not set explicitly in the application config, this property will be populated with the contents of @vendor/yiisoft/extensions.php.
$language the language that is meant to be used for end users. It is recommended that you use IETF language tags. For example, en stands for English, while en-US stands for English (United States).
$layout the layout that should be applied for views in this application. Defaults to 'main'. If this is false, layout will be disabled.
$loadedModules list of loaded modules indexed by their class names.
$name the application name.
$requestedAction the requested Action. If null, it means the request cannot be resolved into an action.
$requestedParams the parameters supplied to the requested action.
$requestedRoute the requested route
$sourceLanguage the language that the application is written in. This mainly refers to the language that the messages and view files are written in.
$state the current application state during a request handling life cycle. This property is managed by the application. Do not modify this property.

Public Methods

Method Description
__construct ( array $config = [] ) Constructor.
coreComponents ( ) Returns the configuration of core application components.
end ( integer $status, Response $response = null ) Terminates the application.
getAssetManager ( ) : AssetManager Returns the asset manager.
getAuthManager ( ) : yii\rbac\ManagerInterface Returns the auth manager for this application.
getCache ( ) : Cache Returns the cache component.
getDb ( ) : Connection Returns the database connection component.
getErrorHandler ( ) : ErrorHandler | yii\console\ErrorHandler Returns the error handler component.
getFormatter ( ) : Formatter Returns the formatter component.
getI18n ( ) : yii\i18n\I18N Returns the internationalization (i18n) component
getLog ( ) : Dispatcher Returns the log dispatcher component.
getMailer ( ) : yii\mail\MailerInterface Returns the mailer component.
getRequest ( ) : Request | yii\console\Request Returns the request component.
getResponse ( ) : Response | yii\console\Response Returns the response component.
getRuntimePath ( ) : string Returns the directory that stores runtime files.
getSecurity ( ) : Security Returns the security component.
getTimeZone ( ) : string Returns the time zone used by this application.
getUniqueId ( ) : string Returns an ID that uniquely identifies this module among all modules within the current application.
getUrlManager ( ) : UrlManager Returns the URL manager for this application.
getVendorPath ( ) : string Returns the directory that stores vendor files.
getView ( ) : View | View Returns the view object.
handleRequest ( Request $request ) : Response Handles the specified request.
init ( )
preInit ( array &$config ) Pre-initializes the application.
run ( ) : integer Runs the application.
setBasePath ( string $path ) Sets the root directory of the application and the @app alias.
setContainer ( array $config ) Configures [[Yii::$container]] with the $config
setRuntimePath ( string $path ) Sets the directory that stores runtime files.
setTimeZone ( string $value ) Sets the time zone used by this application.
setVendorPath ( string $path ) Sets the directory that stores vendor files.

Protected Methods

Method Description
bootstrap ( ) Initializes extensions and executes bootstrap components.
registerErrorHandler ( array &$config ) Registers the errorHandler component as a PHP error handler.

Method Details

__construct() public method

Constructor.
public __construct ( array $config = [] )
$config array name-value pairs that will be used to initialize the object properties. Note that the configuration must contain both [[id]] and [[basePath]].

bootstrap() protected method

This method is called by Application::init after the application has been fully configured. If you override this method, make sure you also call the parent implementation.
protected bootstrap ( )

coreComponents() public method

Returns the configuration of core application components.
See also: set()
public coreComponents ( )

end() public method

This method replaces the exit() function by ensuring the application life cycle is completed before terminating the application.
public end ( integer $status, Response $response = null )
$status integer the exit status (value 0 means normal exit while other values mean abnormal exit).
$response Response the response to be sent. If not set, the default application [[response]] component will be used.

getAssetManager() public method

Returns the asset manager.
public getAssetManager ( ) : AssetManager
return yii\web\AssetManager the asset manager application component.

getAuthManager() public method

Returns the auth manager for this application.
public getAuthManager ( ) : yii\rbac\ManagerInterface
return yii\rbac\ManagerInterface the auth manager application component. Null is returned if auth manager is not configured.

getCache() public method

Returns the cache component.
public getCache ( ) : Cache
return yii\caching\Cache the cache application component. Null if the component is not enabled.

getDb() public method

Returns the database connection component.
public getDb ( ) : Connection
return yii\db\Connection the database connection.

getErrorHandler() public method

Returns the error handler component.
public getErrorHandler ( ) : ErrorHandler | yii\console\ErrorHandler
return yii\web\ErrorHandler | yii\console\ErrorHandler the error handler application component.

getFormatter() public method

Returns the formatter component.
public getFormatter ( ) : Formatter
return yii\i18n\Formatter the formatter application component.

getI18n() public method

Returns the internationalization (i18n) component
public getI18n ( ) : yii\i18n\I18N
return yii\i18n\I18N the internationalization application component.

getLog() public method

Returns the log dispatcher component.
public getLog ( ) : Dispatcher
return yii\log\Dispatcher the log dispatcher application component.

getMailer() public method

Returns the mailer component.
public getMailer ( ) : yii\mail\MailerInterface
return yii\mail\MailerInterface the mailer application component.

getRequest() public method

Returns the request component.
public getRequest ( ) : Request | yii\console\Request
return yii\web\Request | yii\console\Request the request component.

getResponse() public method

Returns the response component.
public getResponse ( ) : Response | yii\console\Response
return yii\web\Response | yii\console\Response the response component.

getRuntimePath() public method

Returns the directory that stores runtime files.
public getRuntimePath ( ) : string
return string the directory that stores runtime files. Defaults to the "runtime" subdirectory under [[basePath]].

getSecurity() public method

Returns the security component.
public getSecurity ( ) : Security
return Security the security application component.

getTimeZone() public method

This is a simple wrapper of PHP function date_default_timezone_get(). If time zone is not configured in php.ini or application config, it will be set to UTC by default.
See also: http://php.net/manual/en/function.date-default-timezone-get.php
public getTimeZone ( ) : string
return string the time zone used by this application.

getUniqueId() public method

Since this is an application instance, it will always return an empty string.
public getUniqueId ( ) : string
return string the unique ID of the module.

getUrlManager() public method

Returns the URL manager for this application.
public getUrlManager ( ) : UrlManager
return yii\web\UrlManager the URL manager for this application.

getVendorPath() public method

Returns the directory that stores vendor files.
public getVendorPath ( ) : string
return string the directory that stores vendor files. Defaults to "vendor" directory under [[basePath]].

getView() public method

Returns the view object.
public getView ( ) : View | View
return View | View the view application component that is used to render various view files.

handleRequest() abstract public method

This method should return an instance of Response or its child class which represents the handling result of the request.
abstract public handleRequest ( Request $request ) : Response
$request Request the request to be handled
return Response the resulting response

init() public method

public init ( )

preInit() public method

This method is called at the beginning of the application constructor. It initializes several important application properties. If you override this method, please make sure you call the parent implementation.
public preInit ( array &$config )
$config array the application configuration

registerErrorHandler() protected method

Registers the errorHandler component as a PHP error handler.
protected registerErrorHandler ( array &$config )
$config array application config

run() public method

This is the main entrance of an application.
public run ( ) : integer
return integer the exit status (0 means normal, non-zero values mean abnormal)

setBasePath() public method

This method can only be invoked at the beginning of the constructor.
public setBasePath ( string $path )
$path string the root directory of the application.

setContainer() public method

Configures [[Yii::$container]] with the $config
Since: 2.0.11
public setContainer ( array $config )
$config array values given in terms of name-value pairs

setRuntimePath() public method

Sets the directory that stores runtime files.
public setRuntimePath ( string $path )
$path string the directory that stores runtime files.

setTimeZone() public method

This is a simple wrapper of PHP function date_default_timezone_set(). Refer to the php manual for available timezones.
See also: http://php.net/manual/en/function.date-default-timezone-set.php
public setTimeZone ( string $value )
$value string the time zone used by this application.

setVendorPath() public method

Sets the directory that stores vendor files.
public setVendorPath ( string $path )
$path string the directory that stores vendor files.

Property Details

$bootstrap public_oe property

list of components that should be run during the application [[bootstrap()|bootstrapping process]]. Each component may be specified in one of the following formats: - an application component ID as specified via [[components]]. - a module ID as specified via [[modules]]. - a class name. - a configuration array. During the bootstrapping process, each component will be instantiated. If the component class implements BootstrapInterface, its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called.
public $bootstrap

$charset public_oe property

the charset currently used for the application.
public $charset

$controller public_oe property

the currently active controller instance
public $controller

$controllerNamespace public_oe property

the namespace that controller classes are located in. This namespace will be used to load controller classes by prepending it to the controller class name. The default namespace is app\controllers. Please refer to the guide about class autoloading for more details.
public $controllerNamespace

$extensions public_oe property

list of installed Yii extensions. Each array element represents a single extension with the following structure: php [ 'name' => 'extension name', 'version' => 'version number', 'bootstrap' => 'BootstrapClassName', // optional, may also be a configuration array 'alias' => [ '@alias1' => 'to/path1', '@alias2' => 'to/path2', ], ] The "bootstrap" class listed above will be instantiated during the application [[bootstrap()|bootstrapping process]]. If the class implements BootstrapInterface, its [[BootstrapInterface::bootstrap()|bootstrap()]] method will be also be called. If not set explicitly in the application config, this property will be populated with the contents of @vendor/yiisoft/extensions.php.
public $extensions

$language public_oe property

the language that is meant to be used for end users. It is recommended that you use IETF language tags. For example, en stands for English, while en-US stands for English (United States).
See also: sourceLanguage
public $language

$layout public_oe property

the layout that should be applied for views in this application. Defaults to 'main'. If this is false, layout will be disabled.
public $layout

$loadedModules public_oe property

list of loaded modules indexed by their class names.
public $loadedModules

$name public_oe property

the application name.
public $name

$requestedAction public_oe property

the requested Action. If null, it means the request cannot be resolved into an action.
public $requestedAction

$requestedParams public_oe property

the parameters supplied to the requested action.
public $requestedParams

$requestedRoute public_oe property

the requested route
public $requestedRoute

$sourceLanguage public_oe property

the language that the application is written in. This mainly refers to the language that the messages and view files are written in.
See also: language
public $sourceLanguage

$state public_oe property

the current application state during a request handling life cycle. This property is managed by the application. Do not modify this property.
public $state