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
파일 보기 프로젝트 열기: pradosoft/prado

공개 메소드들

메소드 설명
__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 )