LimeSurvey API - Master branch

ConsoleApplication extends CConsoleApplication
in package
Uses LSApplicationTrait

Table of Contents

Properties

$api  : LimesurveyApi
$config  : mixed
$currentUserId  : mixed

Methods

__construct()  : mixed
Initialize the console application, assemble and store the merged configuration, and prepare runtime helpers.
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.
getAssetManager()  : CAssetManager
getClientScript()  : CClientScript
Returns the client script manager.
getConfig()  : mixed
Returns a configuration variable from the config array or object properties.
getController()  : mixed
This function is implemented since em_core_manager incorrectly requires it to create urls.
getCurrentUserId()  : int|null
get the current id of connected user, check if user exist before return for security
getPluginManager()  : IApplicationComponent
Returns the plugin manager
getPublicBaseUrl()  : string
Returns the relative URL for the application while considering if a "publicurl" config parameter is set to a valid url
getSession()  : mixed
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.
loadHelper()  : void
Loads a helper
setConfig()  : void
Sets a configuration variable into the config
writeAllowedHosts()  : bool
Writes the allowed_hosts.php config file with the given hosts array.

Properties

Methods

__construct()

Initialize the console application, assemble and store the merged configuration, and prepare runtime helpers.

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

Loads default, console-specific, email, version, updater, security, and optional user configuration files, merges them (and any available global settings from the database) into the application's config, ensures a runtimePath is set when absent, sets the webroot path alias, encrypts the emailsmtppassword config value, and loads the common helper.

Parameters
$aApplicationConfig : array<string|int, mixed>|null = null

Application configuration overrides; if runtimePath is not provided it will be set to <tempdir>/runtime based on the loaded defaults.

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.

getAssetManager()

public getAssetManager() : CAssetManager
Return values
CAssetManager

the asset manager component

getClientScript()

Returns the client script manager.

public getClientScript() : CClientScript
Return values
CClientScript

the client script manager

getConfig()

Returns a configuration variable from the config array or object properties.

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

This method searches for the requested configuration value in the following order:

  1. As a property of the current object
  2. In the config array
  3. If not found, returns the provided default value, otherwise false.
Parameters
$name : string|null = null

The name of the configuration variable to retrieve. If null, the default value will be returned.

$default : mixed = false

The default value to return if the configuration variable is not found. Defaults to false.

Tags
access

public

Return values
mixed

The value of the configuration variable if found, otherwise the default value or false if no default value was provided

getController()

This function is implemented since em_core_manager incorrectly requires it to create urls.

public getController() : mixed

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

getPluginManager()

Returns the plugin manager

public getPluginManager() : IApplicationComponent
Return values
IApplicationComponent

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

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.

loadHelper()

Loads a helper

public loadHelper(string $helper) : void
Parameters
$helper : string
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

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.


        
On this page

Search results