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
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство 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.

Méthodes publiques

Méthode 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.

Méthodes protégées

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

Method Details

__construct() public méthode

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 méthode

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 méthode

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

end() public méthode

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 méthode

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

getAuthManager() public méthode

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

getCache() public méthode

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

getDb() public méthode

Returns the database connection component.
public getDb ( ) : Connection
Résultat yii\db\Connection the database connection.

getErrorHandler() public méthode

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

getFormatter() public méthode

Returns the formatter component.
public getFormatter ( ) : Formatter
Résultat yii\i18n\Formatter the formatter application component.

getI18n() public méthode

Returns the internationalization (i18n) component
public getI18n ( ) : yii\i18n\I18N
Résultat yii\i18n\I18N the internationalization application component.

getLog() public méthode

Returns the log dispatcher component.
public getLog ( ) : Dispatcher
Résultat yii\log\Dispatcher the log dispatcher application component.

getMailer() public méthode

Returns the mailer component.
public getMailer ( ) : yii\mail\MailerInterface
Résultat yii\mail\MailerInterface the mailer application component.

getRequest() public méthode

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

getResponse() public méthode

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

getRuntimePath() public méthode

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

getSecurity() public méthode

Returns the security component.
public getSecurity ( ) : Security
Résultat Security the security application component.

getTimeZone() public méthode

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
Résultat string the time zone used by this application.

getUniqueId() public méthode

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

getUrlManager() public méthode

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

getVendorPath() public méthode

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

getView() public méthode

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

handleRequest() abstract public méthode

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
Résultat Response the resulting response

init() public méthode

public init ( )

preInit() public méthode

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 méthode

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

run() public méthode

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

setBasePath() public méthode

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 méthode

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 méthode

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

setTimeZone() public méthode

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 méthode

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