PHP Class Prado\TApplication

TApplication coordinates modules and services, and serves as a configuration context for all Prado components. TApplication uses a configuration file to specify the settings of the application, the modules, the services, the parameters, and so on. TApplication adopts a modular structure. A TApplication instance is a composition of multiple modules. A module is an instance of class implementing {@link IModule} interface. Each module accomplishes certain functionalities that are shared by all Prado components in an application. There are default modules and user-defined modules. The latter offers extreme flexibility of extending TApplication in a plug-and-play fashion. Modules cooperate with each other to serve a user request by following a sequence of lifecycles predefined in TApplication. TApplication has four modes that can be changed by setting {@link setMode Mode} property (in the application configuration file). - Off mode will prevent the application from serving user requests. - Debug mode is mainly used during application development. It ensures the cache is always up-to-date if caching is enabled. It also allows exceptions are displayed with rich context information if they occur. - Normal mode is mainly used during production stage. Exception information will only be recorded in system error logs. The cache is ensured to be up-to-date if it is enabled. - Performance mode is similar to Normal mode except that it does not ensure the cache is up-to-date. TApplication dispatches each user request to a particular service which finishes the actual work for the request with the aid from the application modules. TApplication maintains a lifecycle with the following stages: - [construct] : construction of the application instance - [initApplication] : load application configuration and instantiate modules and the requested service - onBeginRequest : this event happens right after application initialization - onAuthentication : this event happens when authentication is needed for the current request - onAuthenticationComplete : this event happens right after the authentication is done for the current request - onAuthorization : this event happens when authorization is needed for the current request - onAuthorizationComplete : this event happens right after the authorization is done for the current request - onLoadState : this event happens when application state needs to be loaded - onLoadStateComplete : this event happens right after the application state is loaded - onPreRunService : this event happens right before the requested service is to run - runService : the requested service runs - onSaveState : this event happens when application needs to save its state - onSaveStateComplete : this event happens right after the application saves its state - onPreFlushOutput : this event happens right before the application flushes output to client side. - flushOutput : the application flushes output to client side. - onEndRequest : this is the last stage a request is being completed - [destruct] : destruction of the application instance Modules and services can attach their methods to one or several of the above events and do appropriate processing when the events are raised. By this way, the application is able to coordinate the activities of modules and services in the above order. To terminate an application before the whole lifecycle completes, call {@link completeRequest}. Examples: - Create and run a Prado application: $application=new TApplication($configFile); $application->run();
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends TComponent
Afficher le fichier Open project: pradosoft/prado

Méthodes publiques

Méthode Description
__construct ( $basePath = 'protected', $cacheConfig = true, $configType = self::CONFIG_TYPE_XML ) Constructor.
applyConfiguration ( $config, $withinService = false ) Applies an application configuration.
clearGlobalState ( $key ) Clears a global value.
completeRequest ( ) Completes current request processing.
flushOutput ( $continueBuffering = true ) Flushes output to client side.
getApplicationStatePersister ( ) : prado\IStatePersister
getAssetManager ( ) : TAssetManager
getAuthorizationRules ( ) : TAuthorizationRuleCollection
getBasePath ( ) : string
getCache ( ) : ICache
getConfigurationFile ( ) : string
getConfigurationFileExt ( ) : string
getConfigurationFileName ( ) : string
getConfigurationType ( ) : string
getErrorHandler ( ) : TErrorHandler
getGlobalState ( $key, $defaultValue = null ) : mixed Returns a global value.
getGlobalization ( $createIfNotExists = true ) : TGlobalization
getID ( ) : string
getMode ( ) : TApplicationMode
getModule ( $id ) : prado\IModule
getModules ( ) : array Returns a list of application modules indexed by module IDs.
getPageServiceID ( ) : string
getParameters ( ) : TMap Returns the list of application parameters.
getRequest ( ) : THttpRequest
getRequestCompleted ( ) : boolean
getResponse ( ) : THttpResponse
getRuntimePath ( ) : string
getSecurityManager ( ) : TSecurityManager
getService ( ) : prado\IService
getSession ( ) : THttpSession
getUniqueID ( ) : string
getUser ( ) : IUser
onAuthentication ( ) Raises OnAuthentication event.
onAuthenticationComplete ( ) Raises OnAuthenticationComplete event.
onAuthorization ( ) Raises OnAuthorization event.
onAuthorizationComplete ( ) Raises OnAuthorizationComplete event.
onBeginRequest ( ) Raises OnBeginRequest event.
onEndRequest ( ) Raises OnEndRequest event.
onError ( $param ) Raises OnError event.
onLoadState ( ) Raises OnLoadState event.
onLoadStateComplete ( ) Raises OnLoadStateComplete event.
onPreFlushOutput ( ) Raises OnPreFlushOutput event.
onPreRunService ( ) Raises OnPreRunService event.
onSaveState ( ) Raises OnSaveState event.
onSaveStateComplete ( ) Raises OnSaveStateComplete event.
run ( ) Executes the lifecycles of the application.
runService ( ) Runs the requested service.
setApplicationStatePersister ( prado\IStatePersister $persister )
setAssetManager ( TAssetManager $value )
setBasePath ( $value )
setCache ( Prado\Caching\ICache $cache )
setConfigurationFile ( $value )
setConfigurationType ( $value )
setErrorHandler ( TErrorHandler $handler )
setGlobalState ( $key, $value, $defaultValue = null, $forceSave = false ) Sets a global value.
setGlobalization ( TGlobalization $glob )
setID ( $value )
setMode ( $value )
setModule ( $id, prado\IModule $module = null ) Adds a module to application.
setPageServiceID ( $value )
setRequest ( THttpRequest $request )
setResponse ( THttpResponse $response )
setRuntimePath ( $value )
setSecurityManager ( TSecurityManager $sm )
setService ( $value )
setSession ( THttpSession $session )
setUser ( Prado\Security\IUser $user )
startService ( $serviceID ) Starts the specified service.

Méthodes protégées

Méthode Description
getApplicationConfigurationClass ( )
initApplication ( ) Loads configuration and initializes application.
internalLoadModule ( $id, $force = false )
loadGlobals ( ) Loads global values from persistent storage.
resolvePaths ( $basePath ) Resolves application-relevant paths.
saveGlobals ( ) Saves global values into persistent storage.

Method Details

__construct() public méthode

Sets application base path and initializes the application singleton. Application base path refers to the root directory storing application data and code not directly accessible by Web users. By default, the base path is assumed to be the protected directory under the directory containing the current running script.
public __construct ( $basePath = 'protected', $cacheConfig = true, $configType = self::CONFIG_TYPE_XML )

applyConfiguration() public méthode

Applies an application configuration.
public applyConfiguration ( $config, $withinService = false )

clearGlobalState() public méthode

The value cleared will no longer be available in this request and the following requests.
public clearGlobalState ( $key )

completeRequest() public méthode

This method can be used to exit the application lifecycles after finishing the current cycle.
public completeRequest ( )

flushOutput() public méthode

Flushes output to client side.
public flushOutput ( $continueBuffering = true )

getApplicationConfigurationClass() protected méthode

getApplicationStatePersister() public méthode

public getApplicationStatePersister ( ) : prado\IStatePersister
Résultat prado\IStatePersister application state persister

getAssetManager() public méthode

public getAssetManager ( ) : TAssetManager
Résultat Prado\Web\TAssetManager asset manager

getAuthorizationRules() public méthode

public getAuthorizationRules ( ) : TAuthorizationRuleCollection
Résultat TAuthorizationRuleCollection list of authorization rules for the current request

getBasePath() public méthode

public getBasePath ( ) : string
Résultat string the directory containing the application configuration file (absolute path)

getCache() public méthode

public getCache ( ) : ICache
Résultat ICache the cache module, null if cache module is not installed

getConfigurationFile() public méthode

public getConfigurationFile ( ) : string
Résultat string the application configuration file (absolute path)

getConfigurationFileExt() public méthode

public getConfigurationFileExt ( ) : string
Résultat string the application configuration type. default is 'xml'

getConfigurationFileName() public méthode

public getConfigurationFileName ( ) : string
Résultat string the default configuration file name

getConfigurationType() public méthode

public getConfigurationType ( ) : string
Résultat string the application configuration file (absolute path)

getErrorHandler() public méthode

public getErrorHandler ( ) : TErrorHandler
Résultat Prado\Exceptions\TErrorHandler the error handler module

getGlobalState() public méthode

A global value is one that is persistent across users sessions and requests.
public getGlobalState ( $key, $defaultValue = null ) : mixed
Résultat mixed the global value corresponding to $key

getGlobalization() public méthode

public getGlobalization ( $createIfNotExists = true ) : TGlobalization
Résultat Prado\I18N\TGlobalization globalization module

getID() public méthode

public getID ( ) : string
Résultat string application ID

getMode() public méthode

public getMode ( ) : TApplicationMode
Résultat TApplicationMode application mode. Defaults to TApplicationMode::Debug.

getModule() public méthode

public getModule ( $id ) : prado\IModule
Résultat prado\IModule the module with the specified ID, null if not found

getModules() public méthode

Modules that have not been loaded yet are returned as null objects.
public getModules ( ) : array
Résultat array list of loaded application modules, indexed by module IDs

getPageServiceID() public méthode

public getPageServiceID ( ) : string
Résultat string page service ID

getParameters() public méthode

Since the parameters are returned as a {@link \Prado\Collections\TMap} object, you may use the returned result to access, add or remove individual parameters.
public getParameters ( ) : TMap
Résultat Prado\Collections\TMap the list of application parameters

getRequest() public méthode

public getRequest ( ) : THttpRequest
Résultat Prado\Web\THttpRequest the request module

getRequestCompleted() public méthode

public getRequestCompleted ( ) : boolean
Résultat boolean whether the current request is processed.

getResponse() public méthode

public getResponse ( ) : THttpResponse
Résultat Prado\Web\THttpResponse the response module

getRuntimePath() public méthode

public getRuntimePath ( ) : string
Résultat string the directory storing cache data and application-level persistent data. (absolute path)

getSecurityManager() public méthode

public getSecurityManager ( ) : TSecurityManager
Résultat Prado\Security\TSecurityManager the security manager module

getService() public méthode

public getService ( ) : prado\IService
Résultat prado\IService the currently requested service

getSession() public méthode

public getSession ( ) : THttpSession
Résultat Prado\Web\THttpSession the session module, null if session module is not installed

getUniqueID() public méthode

public getUniqueID ( ) : string
Résultat string an ID that uniquely identifies this Prado application from the others

getUser() public méthode

public getUser ( ) : IUser
Résultat IUser the application user

initApplication() protected méthode

Configuration file will be read and parsed (if a valid cached version exists, it will be used instead). Then, modules are created and initialized; Afterwards, the requested service is created and initialized.
protected initApplication ( )

internalLoadModule() protected méthode

protected internalLoadModule ( $id, $force = false )

loadGlobals() protected méthode

This method is invoked when {@link onLoadState OnLoadState} event is raised. After this method, values that are stored in previous requests become available to the current request via {@link getGlobalState}.
protected loadGlobals ( )

onAuthentication() public méthode

This method is invoked when the user request needs to be authenticated.
public onAuthentication ( )

onAuthenticationComplete() public méthode

This method is invoked right after the user request is authenticated.

onAuthorization() public méthode

This method is invoked when the user request needs to be authorized.
public onAuthorization ( )

onAuthorizationComplete() public méthode

This method is invoked right after the user request is authorized.

onBeginRequest() public méthode

At the time when this method is invoked, application modules are loaded and initialized, user request is resolved and the corresponding service is loaded and initialized. The application is about to start processing the user request.
public onBeginRequest ( )

onEndRequest() public méthode

This method is invoked when the application completes the processing of the request.
public onEndRequest ( )

onError() public méthode

This method is invoked when an exception is raised during the lifecycles of the application.
public onError ( $param )

onLoadState() public méthode

This method is invoked when the application needs to load state (probably stored in session).
public onLoadState ( )

onLoadStateComplete() public méthode

This method is invoked right after the application state has been loaded.
public onLoadStateComplete ( )

onPreFlushOutput() public méthode

This method is invoked right before the application flushes output to client.
public onPreFlushOutput ( )

onPreRunService() public méthode

This method is invoked right before the service is to be run.
public onPreRunService ( )

onSaveState() public méthode

This method is invoked when the application needs to save state (probably stored in session).
public onSaveState ( )

onSaveStateComplete() public méthode

This method is invoked right after the application state has been saved.
public onSaveStateComplete ( )

resolvePaths() protected méthode

This method is invoked by the application constructor to determine the application configuration file, application root path and the runtime path.
See also: setBasePath
See also: setRuntimePath
See also: setConfigurationFile
protected resolvePaths ( $basePath )

run() public méthode

This is the main entry function that leads to the running of the whole Prado application.
public run ( )

runService() public méthode

Runs the requested service.
public runService ( )

saveGlobals() protected méthode

This method is invoked when {@link onSaveState OnSaveState} event is raised.
protected saveGlobals ( )

setApplicationStatePersister() public méthode

public setApplicationStatePersister ( prado\IStatePersister $persister )
$persister prado\IStatePersister

setAssetManager() public méthode

public setAssetManager ( TAssetManager $value )
$value Prado\Web\TAssetManager

setBasePath() public méthode

public setBasePath ( $value )

setCache() public méthode

public setCache ( Prado\Caching\ICache $cache )
$cache Prado\Caching\ICache

setConfigurationFile() public méthode

public setConfigurationFile ( $value )

setConfigurationType() public méthode

public setConfigurationType ( $value )

setErrorHandler() public méthode

public setErrorHandler ( TErrorHandler $handler )
$handler Prado\Exceptions\TErrorHandler

setGlobalState() public méthode

A global value is one that is persistent across users sessions and requests. Make sure that the value is serializable and unserializable.
public setGlobalState ( $key, $value, $defaultValue = null, $forceSave = false )

setGlobalization() public méthode

public setGlobalization ( TGlobalization $glob )
$glob Prado\I18N\TGlobalization

setID() public méthode

public setID ( $value )

setMode() public méthode

public setMode ( $value )

setModule() public méthode

Note, this method does not do module initialization.
public setModule ( $id, prado\IModule $module = null )
$module prado\IModule

setPageServiceID() public méthode

public setPageServiceID ( $value )

setRequest() public méthode

public setRequest ( THttpRequest $request )
$request Prado\Web\THttpRequest

setResponse() public méthode

public setResponse ( THttpResponse $response )
$response Prado\Web\THttpResponse

setRuntimePath() public méthode

public setRuntimePath ( $value )

setSecurityManager() public méthode

public setSecurityManager ( TSecurityManager $sm )
$sm Prado\Security\TSecurityManager

setService() public méthode

public setService ( $value )

setSession() public méthode

public setSession ( THttpSession $session )
$session Prado\Web\THttpSession

setUser() public méthode

public setUser ( Prado\Security\IUser $user )
$user Prado\Security\IUser

startService() public méthode

The service instance will be created. Its properties will be initialized and the configurations will be applied, if any.
public startService ( $serviceID )