LimeSurvey API - Master branch

LSYii_Application extends CWebApplication
in package
Uses LSApplicationTrait

Implements global config

Table of Contents

Properties

$baseUrl  : string
$clientScript  : CClientScript
$db  : CDbConnection
$language  : string
$log  : CLogRouter
$pluginManager  : PluginManager
$request  : CHttpRequest
$session  : CHttpSession
$twigRenderer  : LSETwigViewRenderer
$user  : CWebUser
$api  : LimesurveyApi
$config  : mixed
$dbVersion  : int|null
The DB version, used to check if setup is all OK
$plugin  : iPlugin
If a plugin action is accessed through the PluginHelper, store it here.
$currentUserId  : mixed
$surveyId  : mixed

Methods

__construct()  : mixed
Initiates the application
beforeControllerAction()  : bool
The pre-filter for controller actions.
createController()  : mixed
createPublicUrl()  : string
Creates an absolute URL based on the given controller and action information.
createValidatedAbsoluteUrl()  : string|false
Creates an absolute URL that is validated against allowed hosts.
getApi()  : mixed
Get the Api object.
getAvailableConfigs()  : array<string|int, mixed>
Returns the array of available configurations
getConfig()  : string
Returns a config variable from the config
getCurrentUserId()  : int|null
get the current id of connected user, check if user exist before return for security
getPlugin()  : object
Return plugin, if any
getPluginManager()  : PluginManager
Get the pluginManager
getPublicBaseUrl()  : string
Returns the relative URL for the application while considering if a "publicurl" config parameter is set to a valid url
getSurveyId()  : false|int
Get survey survey id by param
getTwigCustomExtensionsConfig()  : mixed
Look for user custom twig extension in upload directory, and add load their manifest in Twig Application and its sandbox TODO: database uploader + admin interface grid view instead of XML parsing.
init()  : mixed
initLanguage()  : mixed
is_file()  : bool
Check if a file (with a full path) is inside a specific directory
isHostAllowed()  : bool
Checks whether a given host name is in the allowed hosts list.
loadAllowedHosts()  : array<string|int, mixed>
Loads the allowed hosts from the application config.
loadConfig()  : void
Loads a config from a file
loadHelper()  : void
Loads a helper
loadLibrary()  : void
Loads a library
onError()  : void
onException()  : void
setConfig()  : void
Sets a configuration variable into the config
setConfigs()  : void
Set the LimeSUrvey config array according to files and DB
setFlashMessage()  : LSYii_Application
Set a 'flash message'.
setLanguage()  : void
For future use, cache the language app wise as well.
setPlugin()  : void
Used by PluginHelper to make the controlling plugin available from everywhere, e.g. from the plugin's models.
writeAllowedHosts()  : bool
Writes the allowed_hosts.php config file with the given hosts array.
createControllerFromShortUrl()  : array<string|int, mixed>|null
Create controller from short url if the route matches a survey alias.
setSessionByDB()  : void
Set the session after start, Limited to DbHttpSession

Properties

$clientScript

public CClientScript $clientScript

CClientScript manages JavaScript and CSS stylesheets for views.

$language

public string $language

Returns the language that the user is using and the application should be targeted to.

$dbVersion

The DB version, used to check if setup is all OK

protected int|null $dbVersion

Methods

__construct()

Initiates the application

public __construct([array<string|int, mixed> $aApplicationConfig = null ]) : mixed
Parameters
$aApplicationConfig : array<string|int, mixed> = null
Tags
access

public

beforeControllerAction()

The pre-filter for controller actions.

public beforeControllerAction(CController $controller, CAction $action) : bool

This method is invoked before the currently requested controller action and all its filters are executed. You may override this method with logic that needs to be done before all controller actions.

Parameters
$controller : CController

the controller

$action : CAction

the action

Return values
bool

whether the action should be executed.

createController()

public createController(mixed $route[, mixed $owner = null ]) : mixed
Parameters
$route : mixed
$owner : mixed = null
Tags
inheritdoc

Special handling for SEO friendly URLs

createPublicUrl()

Creates an absolute URL based on the given controller and action information.

public createPublicUrl(string $route[, array<string|int, mixed> $params = array() ][, string $schema = '' ][, string $ampersand = '&' ]) : string
Parameters
$route : string

the URL route. This should be in the format of 'ControllerID/ActionID'.

$params : array<string|int, mixed> = array()

additional GET parameters (name=>value). Both the name and value will be URL-encoded.

$schema : string = ''

schema to use (e.g. http, https). If empty, the schema used for the current request will be used.

$ampersand : string = '&'

the token separating name-value pairs in the URL.

Return values
string

the constructed URL

createValidatedAbsoluteUrl()

Creates an absolute URL that is validated against allowed hosts.

public createValidatedAbsoluteUrl(string $route[, array<string|int, mixed> $params = array() ][, string $schema = '' ][, string $ampersand = '&' ]) : string|false

This prevents host header injection attacks by ensuring the generated URL uses a trusted host from allowed_hosts.php or the configured publicurl.

Parameters
$route : string

the URL route.

$params : array<string|int, mixed> = array()

additional GET parameters (name=>value).

$schema : string = ''

schema to use (e.g. http, https).

$ampersand : string = '&'

the token separating name-value pairs in the URL.

Return values
string|false

the constructed URL with a validated host, or false if no trusted host is available.

getAvailableConfigs()

Returns the array of available configurations

public getAvailableConfigs() : array<string|int, mixed>
Tags
access

public

Return values
array<string|int, mixed>

getConfig()

Returns a config variable from the config

public getConfig(string $name[, bool|mixed $default = false ]) : string
Parameters
$name : string
$default : bool|mixed = false

Value to return when not found, default is false

Tags
access

public

Return values
string

getCurrentUserId()

get the current id of connected user, check if user exist before return for security

public getCurrentUserId() : int|null
Return values
int|null

user id, 0 mean invalid user

getPlugin()

Return plugin, if any

public getPlugin() : object
Return values
object

getPublicBaseUrl()

Returns the relative URL for the application while considering if a "publicurl" config parameter is set to a valid url

public getPublicBaseUrl([bool $absolute = false ]) : string
Parameters
$absolute : bool = false

whether to return an absolute URL. Defaults to false, meaning returning a relative one.

Return values
string

the relative or the configured public URL for the application

getSurveyId()

Get survey survey id by param

public static getSurveyId([bool $throwError = true ]) : false|int
Parameters
$throwError : bool = true

Whether to throw an error

Return values
false|int

getTwigCustomExtensionsConfig()

Look for user custom twig extension in upload directory, and add load their manifest in Twig Application and its sandbox TODO: database uploader + admin interface grid view instead of XML parsing.

public getTwigCustomExtensionsConfig(mixed $sUsertwigextensionrootdir, mixed $aApplicationConfig) : mixed
Parameters
$sUsertwigextensionrootdir : mixed
$aApplicationConfig : mixed

is_file()

Check if a file (with a full path) is inside a specific directory

public is_file(mixed $filePath[, mixed $baseDir = null ][, mixed $throwException = null ]) : bool
Parameters
$filePath : mixed
$baseDir : mixed = null
$throwException : mixed = null
Return values
bool

isHostAllowed()

Checks whether a given host name is in the allowed hosts list.

public isHostAllowed(string $host) : bool

Lenient when allowed_hosts.php does not exist yet (returns true). Once the file exists with entries, strictly enforces the allowlist. The host from publicurl (if configured) is always auto-included.

Parameters
$host : string

The host name to validate.

Return values
bool

True if the host is allowed, false otherwise.

loadAllowedHosts()

Loads the allowed hosts from the application config.

public loadAllowedHosts() : array<string|int, mixed>

The config key 'allowedHosts' is populated from application/config/allowed_hosts.php (loaded at application startup, same pattern as security.php).

Return values
array<string|int, mixed>

List of allowed host names, or empty array if not configured.

loadConfig()

Loads a config from a file

public loadConfig(string $file) : void
Parameters
$file : string
Tags
access

public

loadHelper()

Loads a helper

public loadHelper(string $helper) : void
Parameters
$helper : string
Tags
access

public

loadLibrary()

Loads a library

public loadLibrary(string $library) : void
Parameters
$library : string

Library name

Tags
access

public

setConfig()

Sets a configuration variable into the config

public setConfig(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed
Tags
access

public

setConfigs()

Set the LimeSUrvey config array according to files and DB

public setConfigs() : void

setFlashMessage()

Set a 'flash message'.

public setFlashMessage(string $message[, string $type = 'success' ]) : LSYii_Application

A flash message will be shown on the next request and can contain a message to tell that the action was successful or not. The message is displayed and cleared when it is shown in the view using the widget: $this->widget('application.extensions.FlashMessage.FlashMessage');

Parameters
$message : string

The message you want to show on next page load

$type : string = 'success'

Type can be 'success','info','warning','danger','error' which relate to the particular bootstrap alert classes - see http://getbootstrap.com/components/#alerts . Note: Option 'error' is synonymous to 'danger'

Return values
LSYii_Application

Provides a fluent interface

setLanguage()

For future use, cache the language app wise as well.

public setLanguage(string $sLanguage) : void
Parameters
$sLanguage : string
Tags
access

public

setPlugin()

Used by PluginHelper to make the controlling plugin available from everywhere, e.g. from the plugin's models.

public setPlugin( $plugin) : void

Corresponds to Yii::app()->getController()

Parameters
$plugin :

writeAllowedHosts()

Writes the allowed_hosts.php config file with the given hosts array.

public writeAllowedHosts(array<string|int, mixed> $hosts) : bool
Parameters
$hosts : array<string|int, mixed>

Array of allowed domain names (no protocol, no port).

Return values
bool

True on success, false on failure.

createControllerFromShortUrl()

Create controller from short url if the route matches a survey alias.

private createControllerFromShortUrl(string $route) : array<string|int, mixed>|null
Parameters
$route : string

the route of the request.

Return values
array<string|int, mixed>|null

setSessionByDB()

Set the session after start, Limited to DbHttpSession

private setSessionByDB(mixed $aApplicationConfig) : void
Parameters
$aApplicationConfig : mixed

        
On this page

Search results