PRADO Component Framework for PHP 5
  • Home
  • About
  • Testimonials
  • Demos
  • Download
  • Documentation
  • Forum
  • Development
  • Tutorials
  • Class Docs
  • API Manual
  • Wiki

Packages

  • None
  • System
    • Caching
    • Collections
    • Data
      • ActiveRecord
        • Relations
        • Scaffold
          • InputBuilder
      • Commom
        • Sqlite
      • Common
        • Mssql
        • Mysql
        • Oracle
        • Pgsql
        • Sqlite
      • DataGateway
      • SqlMap
        • Configuration
        • Statements
    • Exceptions
    • I18N
    • IO
    • Security
    • Util
    • Web
      • Javascripts
      • Services
      • UI
        • ActiveControls
        • WebControls
    • Xml
  • Wsat
    • pages
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo

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
Extended by TApplication

Direct known subclasses

TShellApplication
Package: System
Copyright: Copyright © 2005-2014 PradoSoft
License: http://www.pradosoft.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 3.0
Located at TApplication.php
Methods summary
public
# __construct( string $basePath = 'protected', boolean $cacheConfig = true, mixed $configType = TApplication::CONFIG_TYPE_XML )

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.

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.

Parameters

$basePath
string
application base path or configuration file path. If the parameter is a file, it is assumed to be the application configuration file, and the directory containing the file is treated as the application base path. If it is a directory, it is assumed to be the application base path, and within that directory, a file named application.xml will be looked for. If found, the file is considered as the application configuration file.
$cacheConfig
boolean
whether to cache application configuration. Defaults to true.
$configType

Throws

TConfigurationException
if configuration file cannot be read or the runtime path is invalid.

Overrides

TComponent::__construct()
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.

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.

Parameters

$basePath
string
the application root path or the application configuration file

See

TApplication::setBasePath()
TApplication::setRuntimePath()
TApplication::setConfigurationFile()
public
# run( )

Executes the lifecycles of the application. This is the main entry function that leads to the running of the whole Prado application.

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.

Completes current request processing. This method can be used to exit the application lifecycles after finishing the current cycle.

public boolean
# getRequestCompleted( )

Returns

boolean
whether the current request is processed.
public mixed
# getGlobalState( string $key, mixed $defaultValue = null )

Returns a global value.

Returns a global value.

A global value is one that is persistent across users sessions and requests.

Parameters

$key
string
the name of the value to be returned
$defaultValue
mixed
the default value. If $key is not found, $defaultValue will be returned

Returns

mixed
the global value corresponding to $key
public
# setGlobalState( string $key, mixed $value, mixed $defaultValue = null, boolean $forceSave = false )

Sets a global value.

Sets a global value.

A global value is one that is persistent across users sessions and requests. Make sure that the value is serializable and unserializable.

Parameters

$key
string
the name of the value to be set
$value
mixed
the global value to be set
$defaultValue
mixed
the default value. If $key is not found, $defaultValue will be returned
$forceSave
boolean
wheter to force an immediate GlobalState save. defaults to false
public
# clearGlobalState( string $key )

Clears a global value.

Clears a global value.

The value cleared will no longer be available in this request and the following requests.

Parameters

$key
string
the name of the value to be cleared
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 TApplication::getGlobalState().

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 TApplication::getGlobalState().

protected
# saveGlobals( )

Saves global values into persistent storage. This method is invoked when onSaveState OnSaveState event is raised.

Saves global values into persistent storage. This method is invoked when onSaveState OnSaveState event is raised.

public string
# getID( )

Returns

string
application ID
public
# setID( string $value )

Parameters

$value
string
application ID
public string
# getPageServiceID( )

Returns

string
page service ID
public
# setPageServiceID( string $value )

Parameters

$value
string
page service ID
public string
# getUniqueID( )

Returns

string
an ID that uniquely identifies this Prado application from the others
public TApplicationMode
# getMode( )

Returns

TApplicationMode
application mode. Defaults to TApplicationMode::Debug.
public
# setMode( TApplicationMode $value )

Parameters

$value
TApplicationMode
application mode
public string
# getBasePath( )

Returns

string
the directory containing the application configuration file (absolute path)
public
# setBasePath( string $value )

Parameters

$value
string
the directory containing the application configuration file
public string
# getConfigurationFile( )

Returns

string
the application configuration file (absolute path)
public
# setConfigurationFile( string $value )

Parameters

$value
string
the application configuration file (absolute path)
public string
# getConfigurationType( )

Returns

string
the application configuration file (absolute path)
public
# setConfigurationType( string $value )

Parameters

$value
string
the application configuration type. 'xml' and 'php' are valid values
public string
# getConfigurationFileExt( )

Returns

string
the application configuration type. default is 'xml'
public string
# getConfigurationFileName( )

Returns

string
the default configuration file name
public string
# getRuntimePath( )

Returns

string
the directory storing cache data and application-level persistent data. (absolute path)
public
# setRuntimePath( string $value )

Parameters

$value
string
the directory storing cache data and application-level persistent data. (absolute path)
public IService
# getService( )

Returns

IService
the currently requested service
public
# setService( IService $value )

Parameters

$value
IService
the currently requested service
public
# setModule( string $id, IModule $module = null )

Adds a module to application. Note, this method does not do module initialization.

Adds a module to application. Note, this method does not do module initialization.

Parameters

$id
string
ID of the module
$module
IModule
module object or null if the module has not been loaded yet
public IModule
# getModule( mixed $id )

Returns

IModule
the module with the specified ID, null if not found
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.

Returns a list of application modules indexed by module IDs. Modules that have not been loaded yet are returned as null objects.

Returns

array
list of loaded application modules, indexed by module IDs
public TMap
# getParameters( )

Returns the list of application parameters. Since the parameters are returned as a TMap object, you may use the returned result to access, add or remove individual parameters.

Returns the list of application parameters. Since the parameters are returned as a TMap object, you may use the returned result to access, add or remove individual parameters.

Returns

TMap
the list of application parameters
public THttpRequest
# getRequest( )

Returns

THttpRequest
the request module
public
# setRequest( THttpRequest $request )

Parameters

$request
THttpRequest
the request module
public THttpResponse
# getResponse( )

Returns

THttpResponse
the response module
public
# setResponse( THttpResponse $response )

Parameters

$response
THttpRequest
the request module
public THttpSession
# getSession( )

Returns

THttpSession
the session module, null if session module is not installed
public
# setSession( THttpSession $session )

Parameters

$session
THttpSession
the session module
public TErrorHandler
# getErrorHandler( )

Returns

TErrorHandler
the error handler module
public
# setErrorHandler( TErrorHandler $handler )

Parameters

$handler
TErrorHandler
the error handler module
public TSecurityManager
# getSecurityManager( )

Returns

TSecurityManager
the security manager module
public
# setSecurityManager( TSecurityManager $sm )

Parameters

$sm
TSecurityManager
the security manager module
public TAssetManager
# getAssetManager( )

Returns

TAssetManager
asset manager
public
# setAssetManager( TAssetManager $value )

Parameters

$value
TAssetManager
asset manager
public IStatePersister
# getApplicationStatePersister( )

Returns

IStatePersister
application state persister
public
# setApplicationStatePersister( IStatePersister $persister )

Parameters

$persister
IStatePersister
application state persister
public ICache
# getCache( )

Returns

ICache
the cache module, null if cache module is not installed
public
# setCache( ICache $cache )

Parameters

$cache
ICache
the cache module
public IUser
# getUser( )

Returns

IUser
the application user
public
# setUser( IUser $user )

Parameters

$user
IUser
the application user
public TGlobalization
# getGlobalization( boolean $createIfNotExists = true )

Parameters

$createIfNotExists
boolean
whether to create globalization if it does not exist

Returns

TGlobalization
globalization module
public
# setGlobalization( TGlobalization $glob )

Parameters

$glob
TGlobalization
globalization module
public TAuthorizationRuleCollection
# getAuthorizationRules( )

Returns

TAuthorizationRuleCollection
list of authorization rules for the current request
protected
# getApplicationConfigurationClass( )
protected
# internalLoadModule( mixed $id, mixed $force = false )
public
# applyConfiguration( TApplicationConfiguration $config, boolean $withinService = false )

Applies an application configuration.

Applies an application configuration.

Parameters

$config
TApplicationConfiguration
the configuration
$withinService
boolean
whether the configuration is specified within a service.
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.

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.

Throws

TConfigurationException
if module is redefined of invalid type, or service not defined or of invalid type
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.

Starts the specified service. The service instance will be created. Its properties will be initialized and the configurations will be applied, if any.

Parameters

$serviceID
string
service ID
public
# onError( mixed $param )

Raises OnError event. This method is invoked when an exception is raised during the lifecycles of the application.

Raises OnError event. This method is invoked when an exception is raised during the lifecycles of the application.

Parameters

$param
mixed
event parameter
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.

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.

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.

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.

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.

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).

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.

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.

Raises OnPreRunService event. This method is invoked right before the service is to be run.

public
# runService( )

Runs the requested service.

Runs the requested service.

public
# onSaveState( )

Raises OnSaveState event. This method is invoked when the application needs to save state (probably stored in session).

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.

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.

Raises OnPreFlushOutput event. This method is invoked right before the application flushes output to client.

public
# flushOutput( boolean $continueBuffering = true )

Flushes output to client side.

Flushes output to client side.

Parameters

$continueBuffering
boolean
whether to continue buffering after flush if buffering was active
public
# onEndRequest( )

Raises OnEndRequest event. This method is invoked when the application completes the processing of the request.

Raises OnEndRequest event. This method is invoked when the application completes the processing of the request.

Methods inherited from TComponent
__call(), __destruct(), __get(), __isset(), __set(), __sleep(), __unset(), __wakeup(), addParsedObject(), asa(), attachBehavior(), attachBehaviors(), attachClassBehavior(), attachEventHandler(), canGetProperty(), canSetProperty(), clearBehaviors(), createdOnTemplate(), detachBehavior(), detachBehaviors(), detachClassBehavior(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), evaluateStatements(), fxAttachClassBehavior(), fxDetachClassBehavior(), getAutoGlobalListen(), getBehaviorsEnabled(), getClassHierarchy(), getEventHandlers(), getListeningToGlobalEvents(), getSubProperty(), hasEvent(), hasEventHandler(), hasProperty(), isa(), listen(), raiseEvent(), setSubProperty(), unlisten()
Constants summary
string STATE_OFF 'Off'
#

possible application mode.

possible application mode.

Deprecated

deprecated since version 3.0.4 (use TApplicationMode constants instead)
string STATE_DEBUG 'Debug'
#
string STATE_NORMAL 'Normal'
#
string STATE_PERFORMANCE 'Performance'
#
string PAGE_SERVICE_ID 'page'
#

Page service ID

Page service ID

string CONFIG_FILE_XML 'application.xml'
#

Application configuration file name

Application configuration file name

string CONFIG_FILE_EXT_XML '.xml'
#

File extension for external config files

File extension for external config files

string CONFIG_TYPE_XML 'xml'
#

Configuration file type, application.xml and config.xml

Configuration file type, application.xml and config.xml

string CONFIG_FILE_PHP 'application.php'
#

Application configuration file name

Application configuration file name

string CONFIG_FILE_EXT_PHP '.php'
#

File extension for external config files

File extension for external config files

string CONFIG_TYPE_PHP 'php'
#

Configuration file type, application.php and config.php

Configuration file type, application.php and config.php

string RUNTIME_PATH 'runtime'
#

Runtime directory name

Runtime directory name

string CONFIGCACHE_FILE 'config.cache'
#

Config cache file

Config cache file

string GLOBAL_FILE 'global.cache'
#

Global data file

Global data file

Constants inherited from TComponent
GLOBAL_RAISE_EVENT_LISTENER
Terms of Service | Contact Us
PRADO v3.2.4 API Manual API documentation generated by ApiGen 2.8.0
Copyright © 2006-2014 by the PRADO Group.
Powered by PRADO