PHP Класс 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();
С версии: 3.0
Автор: Qiang Xue ([email protected])
Наследование: extends TComponent
Показать файл Открыть проект

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

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

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

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

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

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

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() публичный Метод

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

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

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

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

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

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

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

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

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

public getApplicationStatePersister ( ) : prado\IStatePersister
Результат prado\IStatePersister application state persister

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

public getAssetManager ( ) : TAssetManager
Результат Prado\Web\TAssetManager asset manager

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

public getAuthorizationRules ( ) : TAuthorizationRuleCollection
Результат TAuthorizationRuleCollection list of authorization rules for the current request

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

public getBasePath ( ) : string
Результат string the directory containing the application configuration file (absolute path)

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

public getCache ( ) : ICache
Результат ICache the cache module, null if cache module is not installed

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

public getConfigurationFile ( ) : string
Результат string the application configuration file (absolute path)

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

public getConfigurationFileExt ( ) : string
Результат string the application configuration type. default is 'xml'

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

public getConfigurationFileName ( ) : string
Результат string the default configuration file name

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

public getConfigurationType ( ) : string
Результат string the application configuration file (absolute path)

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

public getErrorHandler ( ) : TErrorHandler
Результат Prado\Exceptions\TErrorHandler the error handler module

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

A global value is one that is persistent across users sessions and requests.
public getGlobalState ( $key, $defaultValue = null ) : mixed
Результат mixed the global value corresponding to $key

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

public getGlobalization ( $createIfNotExists = true ) : TGlobalization
Результат Prado\I18N\TGlobalization globalization module

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

public getID ( ) : string
Результат string application ID

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

public getMode ( ) : TApplicationMode
Результат TApplicationMode application mode. Defaults to TApplicationMode::Debug.

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

public getModule ( $id ) : prado\IModule
Результат prado\IModule the module with the specified ID, null if not found

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

Modules that have not been loaded yet are returned as null objects.
public getModules ( ) : array
Результат array list of loaded application modules, indexed by module IDs

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

public getPageServiceID ( ) : string
Результат string page service ID

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

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
Результат Prado\Collections\TMap the list of application parameters

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

public getRequest ( ) : THttpRequest
Результат Prado\Web\THttpRequest the request module

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

public getRequestCompleted ( ) : boolean
Результат boolean whether the current request is processed.

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

public getResponse ( ) : THttpResponse
Результат Prado\Web\THttpResponse the response module

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

public getRuntimePath ( ) : string
Результат string the directory storing cache data and application-level persistent data. (absolute path)

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

public getSecurityManager ( ) : TSecurityManager
Результат Prado\Security\TSecurityManager the security manager module

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

public getService ( ) : prado\IService
Результат prado\IService the currently requested service

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

public getSession ( ) : THttpSession
Результат Prado\Web\THttpSession the session module, null if session module is not installed

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

public getUniqueID ( ) : string
Результат string an ID that uniquely identifies this Prado application from the others

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

public getUser ( ) : IUser
Результат IUser the application user

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

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 internalLoadModule ( $id, $force = false )

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

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() публичный Метод

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

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

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

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

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

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

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

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

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() публичный Метод

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

This method is invoked by the application constructor to determine the application configuration file, application root path and the runtime path.
См. также: setBasePath
См. также: setRuntimePath
См. также: setConfigurationFile
protected resolvePaths ( $basePath )

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

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

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

Runs the requested service.
public runService ( )

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

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

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

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

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

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

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

public setBasePath ( $value )

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

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

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

public setConfigurationFile ( $value )

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

public setConfigurationType ( $value )

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

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

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

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 setGlobalization ( TGlobalization $glob )
$glob Prado\I18N\TGlobalization

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

public setID ( $value )

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

public setMode ( $value )

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

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

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

public setPageServiceID ( $value )

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

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

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

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

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

public setRuntimePath ( $value )

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

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

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

public setService ( $value )

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

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

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

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

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

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