class WebApplication extends BaseApplication

Base class for a Joomla! Web application.

Properties

string $charSet
string $mimeType
JDate $modifiedDate
JApplicationWebClient $client

Methods

__construct( Input $input = null, Registry $config = null, JApplicationWebClient $client = null)

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  WebApplication
getInstance( string $name = null)

Returns a reference to the global WebApplication object, only creating it if it doesn't already exist.

initialise( mixed $session = null, mixed $document = null, mixed $language = null, mixed $dispatcher = null)

Initialise the application.

void
execute()

Execute the application.

void
redirect( string $url, integer $status = 303)

Redirect to another URL.

loadConfiguration( mixed $data)

Load an object or array into the application configuration object.

boolean
allowCache( boolean $allow = null)

Set/get cachable state for the response. If $allow is set, sets the cachable state of the response. Always returns the current state.

setHeader( string $name, string $value, boolean $replace = false)

Method to set a response header. If the replace flag is set then all headers with the given name will be replaced by the new one. The headers are stored in an internal array to be sent when the site is sent to the browser.

array
getHeaders()

Method to get the array of response headers to be sent when the response is sent to the client.

clearHeaders()

Method to clear any set response headers.

sendHeaders()

Send the response headers.

setBody( string $content)

Set body content. If body content already defined, this will replace it.

prependBody( string $content)

Prepend content to the body content

appendBody( string $content)

Append content to the body content

mixed
getBody( boolean $asArray = false)

Return the body content

JDocument
getDocument()

Method to get the application document object.

JLanguage
getLanguage()

Method to get the application language object.

JSession
getSession()

Method to get the application session object.

void
flushAssets()

Flush the media version to refresh versionable assets

boolean
isSSLConnection()

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

loadDocument( JDocument $document = null)

Allows the application to load a custom or default document.

loadLanguage( JLanguage $language = null)

Allows the application to load a custom or default language.

loadSession( JSession $session = null)

Allows the application to load a custom or default session.

void
afterSessionStart()

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

Details

__construct( Input $input = null, Registry $config = null, JApplicationWebClient $client = null)

Class constructor.

Parameters

Input $input An optional argument to provide dependency injection for the application's input object. If the argument is a \JInput object that object will become the application's input object, otherwise a default input object is created.
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.
JApplicationWebClient $client An optional argument to provide dependency injection for the application's client object. If the argument is a \JApplicationWebClient object that object will become the application's client object, otherwise a default client 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 WebApplication getInstance( string $name = null)

Returns a reference to the global WebApplication object, only creating it if it doesn't already exist.

This method must be invoked as: $web = WebApplication::getInstance();

Parameters

string $name The name (optional) of the JApplicationWeb class to instantiate.

Return Value

WebApplication

WebApplication initialise( mixed $session = null, mixed $document = null, mixed $language = null, mixed $dispatcher = null)

Initialise the application.

Parameters

mixed $session An optional argument to provide dependency injection for the application's session object. If the argument is a \JSession object that object will become the application's session object, if it is false then there will be no session object, and if it is null then the default session object will be created based on the application's loadSession() method.
mixed $document An optional argument to provide dependency injection for the application's document object. If the argument is a \JDocument object that object will become the application's document object, if it is false then there will be no document object, and if it is null then the default document object will be created based on the application's loadDocument() method.
mixed $language An optional argument to provide dependency injection for the application's language object. If the argument is a \JLanguage object that object will become the application's language object, if it is false then there will be no language object, and if it is null then the default language object will be created based on the application's loadLanguage() method.
mixed $dispatcher An optional argument to provide dependency injection for the application's event dispatcher. If the argument is a \JEventDispatcher object that object will become the application's event dispatcher, if it is null then the default event dispatcher will be created based on the application's loadDispatcher() method.

Return Value

WebApplication Instance of $this to allow chaining.

See also

WebApplication::loadSession()
WebApplication::loadDocument()
WebApplication::loadLanguage()
WebApplication::loadDispatcher()

void execute()

Execute the application.

Return Value

void

void redirect( string $url, integer $status = 303)

Redirect to another URL.

If the headers have not been sent the redirect will be accomplished using a "301 Moved Permanently" or "303 See Other" 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.
integer $status The HTTP 1.1 status code to be provided. 303 is assumed by default.

Return Value

void

WebApplication loadConfiguration( mixed $data)

Load an object or array into the application configuration object.

Parameters

mixed $data Either an array or object to be loaded into the configuration object.

Return Value

WebApplication Instance of $this to allow chaining.

boolean allowCache( boolean $allow = null)

Set/get cachable state for the response. If $allow is set, sets the cachable state of the response. Always returns the current state.

Parameters

boolean $allow True to allow browser caching.

Return Value

boolean

WebApplication setHeader( string $name, string $value, boolean $replace = false)

Method to set a response header. If the replace flag is set then all headers with the given name will be replaced by the new one. The headers are stored in an internal array to be sent when the site is sent to the browser.

Parameters

string $name The name of the header to set.
string $value The value of the header to set.
boolean $replace True to replace any headers with the same name.

Return Value

WebApplication Instance of $this to allow chaining.

array getHeaders()

Method to get the array of response headers to be sent when the response is sent to the client.

Return Value

array *

WebApplication clearHeaders()

Method to clear any set response headers.

Return Value

WebApplication Instance of $this to allow chaining.

WebApplication sendHeaders()

Send the response headers.

Return Value

WebApplication Instance of $this to allow chaining.

WebApplication setBody( string $content)

Set body content. If body content already defined, this will replace it.

Parameters

string $content The content to set as the response body.

Return Value

WebApplication Instance of $this to allow chaining.

WebApplication prependBody( string $content)

Prepend content to the body content

Parameters

string $content The content to prepend to the response body.

Return Value

WebApplication Instance of $this to allow chaining.

WebApplication appendBody( string $content)

Append content to the body content

Parameters

string $content The content to append to the response body.

Return Value

WebApplication Instance of $this to allow chaining.

mixed getBody( boolean $asArray = false)

Return the body content

Parameters

boolean $asArray True to return the body as an array of strings.

Return Value

mixed The response body either as an array or concatenated string.

JDocument getDocument()

Method to get the application document object.

Return Value

JDocument The document object

JLanguage getLanguage()

Method to get the application language object.

Return Value

JLanguage The language object

JSession getSession()

Method to get the application session object.

Return Value

JSession The session object

void flushAssets()

Flush the media version to refresh versionable assets

Return Value

void

boolean isSSLConnection()

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

Return Value

boolean True if using SSL, false if not.

WebApplication loadDocument( JDocument $document = null)

Allows the application to load a custom or default document.

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 a document, if required, based on more specific needs.

Parameters

JDocument $document An optional document object. If omitted, the factory document is created.

Return Value

WebApplication This method is chainable.

WebApplication loadLanguage( JLanguage $language = null)

Allows the application to load a custom or default language.

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 a language, if required, based on more specific needs.

Parameters

JLanguage $language An optional language object. If omitted, the factory language is created.

Return Value

WebApplication This method is chainable.

WebApplication loadSession( JSession $session = null)

Allows the application to load a custom or default session.

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 a session, if required, based on more specific needs.

Parameters

JSession $session An optional session object. If omitted, the session is created.

Return Value

WebApplication This method is chainable.

void afterSessionStart()

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

Return Value

void