class SiteApplication extends CMSApplication

Joomla! Site Application class

Properties

string $charSet from WebApplication
string $mimeType from WebApplication
JDate $modifiedDate from WebApplication
JApplicationWebClient $client from WebApplication
string $scope The scope of the application. from CMSApplication

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

void
checkSession()

Checks the user session.

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

Enqueue a system message.

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

Gets a configuration value.

integer
getClientId()

Gets the client id of the current running application.

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

Return a reference to the \JMenu object.

array
getMessageQueue( boolean $clear = false)

Get the system message queue.

string
getName()

Gets the name of the current running application.

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

Return a reference to the \JPathway object.

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

Return a reference to the \JRouter object.

mixed
getTemplate( boolean $params = false)

Gets the name of the current template.

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

Gets a user state.

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

Gets the value of a user state variable.

boolean
isAdmin()

Is admin interface?

boolean
isSite()

Is site interface?

boolean
isHttpsForced( integer $clientId = null)

Checks if HTTPS is forced in the client configuration.

boolean
isClient( string $identifier)

Check the client interface by name.

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

Login authentication function

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

Logout authentication function.

mixed
setUserState( string $key, mixed $value)

Sets the value of a user state variable.

string
toString( boolean $compress = false)

Sends all headers prior to returning the string

void
dispatch( string $component = null)

Dispatch the application

boolean
getDetectBrowser()

Return the current state of the detect browser option.

boolean
getLanguageFilter()

Return the current state of the language filter.

Registry
getPageParameters( string $option = null)

Get the application parameters

Registry
getParams( string $option = null)

Get the application parameters

boolean
setDetectBrowser( boolean $state = false)

Set the current state of the detect browser option.

boolean
setLanguageFilter( boolean $state = false)

Set the current state of the language filter.

void
setTemplate( string $template, mixed $styleParams = null)

Overrides the default template that would be used

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 CMSApplication object, only creating it if it doesn't already exist.

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

Parameters

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

Return Value

WebApplication

Exceptions

RuntimeException

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

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

Exceptions

RuntimeException

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

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

Gets a configuration value.

Parameters

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

Return Value

mixed The user state.

integer getClientId()

Gets the client id of the current running application.

Return Value

integer A client identifier.

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

Return a reference to the \JMenu object.

Parameters

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

Return Value

JMenu|null

array getMessageQueue( boolean $clear = false)

Get the system message queue.

Parameters

boolean $clear Clear the messages currently attached to the application object

Return Value

array The system message queue.

string getName()

Gets the name of the current running application.

Return Value

string The name of the application.

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

Return a reference to the \JPathway object.

Parameters

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

Return Value

JPathway|null

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

Return a reference to the \JRouter object.

Parameters

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

Return Value

JRouter|null

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.

Exceptions

InvalidArgumentException

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 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 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 isHttpsForced( integer $clientId = null)

Checks if HTTPS is forced in the client configuration.

Parameters

integer $clientId An optional client id (defaults to current application client).

Return Value

boolean True if is forced for the client, false otherwise.

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.

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

Login authentication function

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 setUserState( string $key, mixed $value)

Sets the value of a user state variable.

Parameters

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

Return Value

mixed The previous state, if one existed.

string toString( boolean $compress = false)

Sends all headers prior to returning the string

Parameters

boolean $compress If true, compress the data

Return Value

string

void dispatch( string $component = null)

Dispatch the application

Parameters

string $component The component which is being rendered.

Return Value

void

boolean getDetectBrowser()

Return the current state of the detect browser option.

Return Value

boolean

boolean getLanguageFilter()

Return the current state of the language filter.

Return Value

boolean

Registry getPageParameters( string $option = null)

Get the application parameters

Parameters

string $option The component option

Return Value

Registry The parameters object

Registry getParams( string $option = null)

Get the application parameters

Parameters

string $option The component option

Return Value

Registry The parameters object

boolean setDetectBrowser( boolean $state = false)

Set the current state of the detect browser option.

Parameters

boolean $state The new state of the detect browser option

Return Value

boolean The previous state

boolean setLanguageFilter( boolean $state = false)

Set the current state of the language filter.

Parameters

boolean $state The new state of the language filter

Return Value

boolean The previous state

void setTemplate( string $template, mixed $styleParams = null)

Overrides the default template that would be used

Parameters

string $template The template name
mixed $styleParams The template style parameters

Return Value

void