class JApplication extends BaseApplication

Base class for a Joomla! application.

Acts as a Factory class for application specific objects and provides many supporting API functions. Derived clases should supply the route(), dispatch() and render() functions.

Properties

string $scope The scope of the application.
string $requestTime The time the request was made.
integer $startTime The time the request was made as Unix timestamp.
JApplicationWebClient $client The application client object.

Methods

__construct( Registry $config = array())

Class constructor.

mixed
getIdentity()

Get the application identity.

registerEvent( string $event, callable $handler)

Registers a handler to a particular event group.

array
triggerEvent( string $event, array $args = null)

Calls all handlers associated with an event group.

loadDispatcher( JEventDispatcher $dispatcher = null)

Allows the application to load a custom or default dispatcher.

loadIdentity( JUser $identity = null)

Allows the application to load a custom or default identity.

static  JApplicationCms
getInstance( mixed $client, array $config = array(), string $prefix = 'J')

Returns the global JApplicationCms object, only creating it if it doesn't already exist.

void
initialise( array $options = array())

Initialise the application.

void
route()

Route the application.

void
dispatch( string $component = null)

Dispatch the application.

void
render()

Render the application.

void
redirect( string $url, string $msg = '', string $msgType = 'message', boolean $moved = false)

Redirect to another URL.

void
enqueueMessage( string $msg, string $type = 'message')

Enqueue a system message.

array
getMessageQueue()

Get the system message queue.

mixed
getCfg( string $varname, string $default = null)

Gets a configuration value.

string
getName()

Method to get the application name.

mixed
getUserState( string $key, mixed $default = null)

Gets a user state.

mixed
setUserState( string $key, string $value)

Sets the value of a user state variable.

mixed
getUserStateFromRequest( string $key, string $request, string $default = null, string $type = 'none')

Gets the value of a user state variable.

boolean|JException
login( array $credentials, array $options = array())

Login authentication function.

boolean
logout( integer $userid = null, array $options = array())

Logout authentication function.

mixed
getTemplate( boolean $params = false)

Gets the name of the current template.

static  JRouter|null
getRouter( string $name = null, array $options = array())

Returns the application JRouter object.

static  string
stringURLSafe( string $string)

This method transliterates a string into a URL safe string or returns a URL safe UTF-8 string based on the global configuration

JPathway|null
getPathway( string $name = null, array $options = array())

Returns the application JPathway object.

JMenu|null
getMenu( string $name = null, array $options = array())

Returns the application JPathway object.

static  string
getHash( string $seed)

Provides a secure hash based on a seed

void
checkSession()

Checks the user session.

void
afterSessionStart()

After the session has been started we need to populate it with some default values.

integer
getClientId()

Gets the client id of the current running application.

boolean
isAdmin()

Is admin interface?

boolean
isSite()

Is site interface?

boolean
isClient( string $identifier)

Check the client interface by name.

static  boolean
isWinOs()

Method to determine if the host OS is Windows

boolean
isSSLConnection()

Determine if we are using a secure (SSL) connection.

string
__toString()

Returns the response as a string.

Details

__construct( Registry $config = array())

Class constructor.

Parameters

Registry $config An optional argument to provide dependency injection for the application's config object. If the argument is a Registry object that object will become the application's config object, otherwise a default config object is created.

mixed getIdentity()

Get the application identity.

Return Value

mixed A \JUser object or null.

BaseApplication registerEvent( string $event, callable $handler)

Registers a handler to a particular event group.

Parameters

string $event The event name.
callable $handler The handler, a function or an instance of an event object.

Return Value

BaseApplication The application to allow chaining.

array triggerEvent( string $event, array $args = null)

Calls all handlers associated with an event group.

Parameters

string $event The event name.
array $args An array of arguments (optional).

Return Value

array An array of results from each function call, or null if no dispatcher is defined.

BaseApplication loadDispatcher( JEventDispatcher $dispatcher = null)

Allows the application to load a custom or default dispatcher.

The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create event dispatchers, if required, based on more specific needs.

Parameters

JEventDispatcher $dispatcher An optional dispatcher object. If omitted, the factory dispatcher is created.

Return Value

BaseApplication This method is chainable.

BaseApplication loadIdentity( JUser $identity = null)

Allows the application to load a custom or default identity.

The logic and options for creating this object are adequately generic for default cases but for many applications it will make sense to override this method and create an identity, if required, based on more specific needs.

Parameters

JUser $identity An optional identity object. If omitted, the factory user is created.

Return Value

BaseApplication This method is chainable.

static JApplicationCms getInstance( mixed $client, array $config = array(), string $prefix = 'J')

Returns the global JApplicationCms object, only creating it if it doesn't already exist.

Parameters

mixed $client A client identifier or name.
array $config An optional associative array of configuration settings.
string $prefix A prefix for class names

Return Value

JApplicationCms A JApplicationCms object.

void initialise( array $options = array())

Initialise the application.

Parameters

array $options An optional associative array of configuration settings.

Return Value

void

void route()

Route the application.

Routing is the process of examining the request environment to determine which component should receive the request. The component optional parameters are then set in the request object to be processed when the application is being dispatched.

Return Value

void

void dispatch( string $component = null)

Dispatch the application.

Dispatching is the process of pulling the option from the request object and mapping them to a component. If the component does not exist, it handles determining a default component to dispatch.

Parameters

string $component The component to dispatch.

Return Value

void

void render()

Render the application.

Rendering is the process of pushing the document buffers into the template placeholders, retrieving data from the document and pushing it into the JResponse buffer.

Return Value

void

void redirect( string $url, string $msg = '', string $msgType = 'message', boolean $moved = false)

Redirect to another URL.

Optionally enqueues a message in the system message queue (which will be displayed the next time a page is loaded) using the enqueueMessage method. If the headers have not been sent the redirect will be accomplished using a "301 Moved Permanently" code in the header pointing to the new location. If the headers have already been sent this will be accomplished using a JavaScript statement.

Parameters

string $url The URL to redirect to. Can only be http/https URL
string $msg An optional message to display on redirect.
string $msgType An optional message type. Defaults to message.
boolean $moved True if the page is 301 Permanently Moved, otherwise 303 See Other is assumed.

Return Value

void Calls exit().

See also

JApplication::enqueueMessage()

void enqueueMessage( string $msg, string $type = 'message')

Enqueue a system message.

Parameters

string $msg The message to enqueue.
string $type The message type. Default is message.

Return Value

void

array getMessageQueue()

Get the system message queue.

Return Value

array The system message queue.

mixed getCfg( string $varname, string $default = null)

Gets a configuration value.

An example is in application/japplication-getcfg.php Getting a configuration

Parameters

string $varname The name of the value to get.
string $default Default value to return

Return Value

mixed The user state.

string getName()

Method to get the application name.

The dispatcher name is by default parsed using the classname, or it can be set by passing a $config['name'] in the class constructor.

Return Value

string The name of the dispatcher.

mixed getUserState( string $key, mixed $default = null)

Gets a user state.

Parameters

string $key The path of the state.
mixed $default Optional default value, returned if the internal value is null.

Return Value

mixed The user state or null.

mixed setUserState( string $key, string $value)

Sets the value of a user state variable.

Parameters

string $key The path of the state.
string $value The value of the variable.

Return Value

mixed The previous state, if one existed.

mixed getUserStateFromRequest( string $key, string $request, string $default = null, string $type = 'none')

Gets the value of a user state variable.

Parameters

string $key The key of the user state variable.
string $request The name of the variable passed in a request.
string $default The default value for the variable if not found. Optional.
string $type Filter for the variable, for valid values see {@link JFilterInput::clean()}. Optional.

Return Value

mixed The request user state.

boolean|JException login( array $credentials, array $options = array())

Login authentication function.

Username and encoded password are passed the onUserLogin event which is responsible for the user validation. A successful validation updates the current session record with the user's details.

Username and encoded password are sent as credentials (along with other possibilities) to each observer (authentication plugin) for user validation. Successful validation will update the current session with the user details.

Parameters

array $credentials Array('username' => string, 'password' => string)
array $options Array('remember' => boolean)

Return Value

boolean|JException True on success, false if failed or silent handling is configured, or a JException object on authentication error.

boolean logout( integer $userid = null, array $options = array())

Logout authentication function.

Passed the current user information to the onUserLogout event and reverts the current session record back to 'anonymous' parameters. If any of the authentication plugins did not successfully complete the logout routine then the whole method fails. Any errors raised should be done in the plugin as this provides the ability to give much more information about why the routine may have failed.

Parameters

integer $userid The user to load - Can be an integer or string - If string, it is converted to ID automatically
array $options Array('clientid' => array of client id's)

Return Value

boolean True on success

mixed getTemplate( boolean $params = false)

Gets the name of the current template.

Parameters

boolean $params An optional associative array of configuration settings

Return Value

mixed System is the fallback.

static JRouter|null getRouter( string $name = null, array $options = array())

Returns the application JRouter object.

Parameters

string $name The name of the application.
array $options An optional associative array of configuration settings.

Return Value

JRouter|null A JRouter object

static string stringURLSafe( string $string)

This method transliterates a string into a URL safe string or returns a URL safe UTF-8 string based on the global configuration

Parameters

string $string String to process

Return Value

string Processed string

JPathway|null getPathway( string $name = null, array $options = array())

Returns the application JPathway object.

Parameters

string $name The name of the application.
array $options An optional associative array of configuration settings.

Return Value

JPathway|null A JPathway object

JMenu|null getMenu( string $name = null, array $options = array())

Returns the application JPathway object.

Parameters

string $name The name of the application/client.
array $options An optional associative array of configuration settings.

Return Value

JMenu|null JMenu object.

static string getHash( string $seed)

Provides a secure hash based on a seed

Parameters

string $seed Seed string.

Return Value

string A secure hash

void checkSession()

Checks the user session.

If the session record doesn't exist, initialise it. If session is new, create session variables

Return Value

void

void afterSessionStart()

After the session has been started we need to populate it with some default values.

Return Value

void

integer getClientId()

Gets the client id of the current running application.

Return Value

integer A client identifier.

boolean isAdmin()

Is admin interface?

Return Value

boolean True if this application is administrator.

boolean isSite()

Is site interface?

Return Value

boolean True if this application is site.

boolean isClient( string $identifier)

Check the client interface by name.

Parameters

string $identifier String identifier for the application interface

Return Value

boolean True if this application is of the given type client interface.

static boolean isWinOs()

Method to determine if the host OS is Windows

Return Value

boolean True if Windows OS

boolean isSSLConnection()

Determine if we are using a secure (SSL) connection.

Return Value

boolean True if using SSL, false if not.

string __toString()

Returns the response as a string.

Return Value

string The response