Class TApplication
TApplication class.
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
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 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 TApplication::completeRequest()
.
Examples:
- Create and run a Prado application:
$application=new TApplication($configFile); $application->run();
- TComponent
-
TApplication
Direct known subclasses
TShellApplicationCopyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at TApplication.php
public
|
#
__construct( string $basePath = 'protected', boolean $cacheConfig = true, mixed $configType =
Constructor. 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. |
protected
|
#
resolvePaths( string $basePath )
Resolves application-relevant paths. This method is invoked by the application constructor to determine the application configuration file, application root path and the runtime path. |
public
|
#
run( )
Executes the lifecycles of the application. This is the main entry function that leads to the running of the whole Prado application. |
public
|
#
completeRequest( )
Completes current request processing. This method can be used to exit the application lifecycles after finishing the current cycle. |
public
boolean
|
|
public
mixed
|
|
public
|
#
setGlobalState( string $key, mixed $value, mixed $defaultValue = null, boolean $forceSave = false )
Sets a global value. |
public
|
|
protected
|
#
loadGlobals( )
Loads global values from persistent storage. This method is invoked when
onLoadState OnLoadState event is raised. After this method, values that
are stored in previous requests become available to the current request via
|
protected
|
#
saveGlobals( )
Saves global values into persistent storage. This method is invoked when onSaveState OnSaveState event is raised. |
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
array
|
#
getModules( )
Returns a list of application modules indexed by module IDs. Modules that have not been loaded yet are returned as null objects. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
protected
|
|
protected
|
|
public
|
#
applyConfiguration(
Applies an application configuration. |
protected
|
#
initApplication( )
Loads configuration and initializes application. 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. |
public
|
#
startService( string $serviceID )
Starts the specified service. The service instance will be created. Its properties will be initialized and the configurations will be applied, if any. |
public
|
#
onError( mixed $param )
Raises OnError event. This method is invoked when an exception is raised during the lifecycles of the application. |
public
|
#
onBeginRequest( )
Raises OnBeginRequest event. 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
|
#
onAuthentication( )
Raises OnAuthentication event. This method is invoked when the user request needs to be authenticated. |
public
|
#
onAuthenticationComplete( )
Raises OnAuthenticationComplete event. This method is invoked right after the user request is authenticated. |
public
|
#
onAuthorization( )
Raises OnAuthorization event. This method is invoked when the user request needs to be authorized. |
public
|
#
onAuthorizationComplete( )
Raises OnAuthorizationComplete event. This method is invoked right after the user request is authorized. |
public
|
#
onLoadState( )
Raises OnLoadState event. This method is invoked when the application needs to load state (probably stored in session). |
public
|
#
onLoadStateComplete( )
Raises OnLoadStateComplete event. This method is invoked right after the application state has been loaded. |
public
|
#
onPreRunService( )
Raises OnPreRunService event. This method is invoked right before the service is to be run. |
public
|
|
public
|
#
onSaveState( )
Raises OnSaveState event. This method is invoked when the application needs to save state (probably stored in session). |
public
|
#
onSaveStateComplete( )
Raises OnSaveStateComplete event. This method is invoked right after the application state has been saved. |
public
|
#
onPreFlushOutput( )
Raises OnPreFlushOutput event. This method is invoked right before the application flushes output to client. |
public
|
|
public
|
#
onEndRequest( )
Raises OnEndRequest event. This method is invoked when the application completes the processing of the request. |
string |
STATE_OFF |
'Off' |
#
possible application mode. |
string |
STATE_DEBUG |
'Debug' |
|
string |
STATE_NORMAL |
'Normal' |
|
string |
STATE_PERFORMANCE |
'Performance' |
|
string |
PAGE_SERVICE_ID |
'page' |
#
Page service ID |
string |
CONFIG_FILE_XML |
'application.xml' |
#
Application configuration file name |
string |
CONFIG_FILE_EXT_XML |
'.xml' |
#
File extension for external config files |
string |
CONFIG_TYPE_XML |
'xml' |
#
Configuration file type, application.xml and config.xml |
string |
CONFIG_FILE_PHP |
'application.php' |
#
Application configuration file name |
string |
CONFIG_FILE_EXT_PHP |
'.php' |
#
File extension for external config files |
string |
CONFIG_TYPE_PHP |
'php' |
#
Configuration file type, application.php and config.php |
string |
RUNTIME_PATH |
'runtime' |
#
Runtime directory name |
string |
CONFIGCACHE_FILE |
'config.cache' |
#
Config cache file |
string |
GLOBAL_FILE |
'global.cache' |
#
Global data file |
GLOBAL_RAISE_EVENT_LISTENER
|