PHP Class Contao\System

The class provides miscellaneous methods that are used all throughout the application. It is the base class of the Contao library which provides the central "import" method to load other library classes. Usage: class MyClass extends \System { public function __construct() { $this->import('Database'); } }
Show file Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrCache array Cache
$arrImageSizes array Available image sizes
$arrLanguageFiles array Loaded language files
$arrLanguages array Available languages
$arrObjects array Default libraries
$arrStaticObjects array Static objects
$objContainer Symfony\Component\DependencyInjection\ContainerInterface Container

Public Methods

Method Description
__get ( string $strKey ) : mixed | null Get an object property
addToUrl ( string $strRequest ) : string Add a request string to the current URL
anonymizeIp ( string $strIp ) : string Anonymize an IP address by overriding the last chunk
convertXlfToPhp ( string $strName, string $strLanguage, boolean $blnLoad = false ) : string Convert an .xlf file into a PHP language file
disableModule ( ) : boolean Disable a back end module
enableModule ( ) : boolean Enable a back end module
getContainer ( ) : Symfony\Component\DependencyInjection\ContainerInterface Return the container object
getCountries ( ) : array Return the countries as array
getFormattedNumber ( mixed $varNumber, integer $intDecimals = 2 ) : mixed Format a number
getImageSizes ( ) : array Return all image sizes as array
getIndexFreeRequest ( boolean $blnAmpersand = true ) : string Return the request string without the script name
getLanguages ( boolean $blnInstalledOnly = false ) : array Return the available languages as array
getModelClassFromTable ( string $strTable ) : string Compile a Model class name from a table name (e.g. tl_form_field becomes FormFieldModel)
getReadableSize ( integer $intSize, integer $intDecimals = 1 ) : string Convert a byte value into a human readable format
getReferer ( boolean $blnEncodeAmpersands = false, string $strTable = null ) : string Return the referer URL and optionally encode ampersands
getSessionHash ( string $strCookie ) : string Return the session hash
getTimeZones ( ) : array Return the timezones as array
importStatic ( string $strClass, string $strKey = null, boolean $blnForce = false ) : object Import a library in non-object context
isInstalledLanguage ( boolean $strLanguage ) : boolean Check whether a language is installed
loadLanguageFile ( string $strName, boolean $strLanguage = null, boolean $blnNoCache = false ) Load a set of language files
log ( string $strText, string $strFunction, string $strCategory ) Add a log entry to the database
parseDate ( string $strFormat, integer $intTstamp = null ) : string Parse a date format string and translate textual representations
redirect ( string $strLocation, integer $intStatus = 303 ) Redirect to another page
reload ( ) Reload the current page
setContainer ( Symfony\Component\DependencyInjection\ContainerInterface $container ) Set the container object
setCookie ( string $strName, mixed $varValue, integer $intExpires, string $strPath = null, string $strDomain = null, boolean $blnSecure = false, boolean $blnHttpOnly = false ) Set a cookie
splitFriendlyName ( string $strEmail ) : array Split a friendly-name e-address and return name and e-mail as array
urlEncode ( string $strPath ) : string Urlencode a file path preserving slashes

Protected Methods

Method Description
__construct ( ) Import the Config and Session instances
addConfirmationMessage ( string $strMessage ) Add a confirmation message
addErrorMessage ( string $strMessage ) Add an error message
addInfoMessage ( string $strMessage ) Add an info message
addMessage ( string $strMessage, string $strType ) Add a message
addNewMessage ( string $strMessage ) Add a new message
addRawMessage ( string $strMessage ) Add an unformatted message
getMessageTypes ( ) : array Return all available message types
getMessages ( string $strScope = TL_MODE ) : string Return all messages as HTML
idnaDecode ( string $strDomain ) : string Decode an internationalized domain name
idnaEncode ( string $strDomain ) : string Encode an internationalized domain name
idnaEncodeEmail ( string $strEmail ) : string Encode the domain in an e-mail address
idnaEncodeUrl ( string $strUrl ) : string Encode the domain in an URL
import ( string $strClass, string $strKey = null, boolean $blnForce = false ) Import a library and make it accessible by its name or an optional key
isValidEmailAddress ( string $strEmail ) : boolean Validate an e-mail address
readPhpFileWithoutTags ( string $strName ) : string Read the contents of a PHP file, stripping the opening and closing PHP tags
resetMessages ( ) Reset the message system

Method Details

__construct() protected method

Import the Config and Session instances
protected __construct ( )

__get() public method

Lazy load the Input and Environment libraries (which are now static) and only include them as object property if an old module requires it
public __get ( string $strKey ) : mixed | null
$strKey string The property name
return mixed | null The property value or null

addConfirmationMessage() protected method

Add a confirmation message
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::addConfirmation() instead.
protected addConfirmationMessage ( string $strMessage )
$strMessage string The confirmation

addErrorMessage() protected method

Add an error message
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::addError() instead.
protected addErrorMessage ( string $strMessage )
$strMessage string The error message

addInfoMessage() protected method

Add an info message
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::addInfo() instead.
protected addInfoMessage ( string $strMessage )
$strMessage string The info message

addMessage() protected method

Add a message
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::add() instead.
protected addMessage ( string $strMessage, string $strType )
$strMessage string The message
$strType string The message type

addNewMessage() protected method

Add a new message
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::addNew() instead.
protected addNewMessage ( string $strMessage )
$strMessage string The new message

addRawMessage() protected method

Add an unformatted message
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::addRaw() instead.
protected addRawMessage ( string $strMessage )
$strMessage string The unformatted message

addToUrl() public static method

Add a request string to the current URL
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Controller::addToUrl() instead.
public static addToUrl ( string $strRequest ) : string
$strRequest string The string to be added
return string The new URL

anonymizeIp() public static method

Anonymize an IP address by overriding the last chunk
public static anonymizeIp ( string $strIp ) : string
$strIp string The IP address
return string The encoded IP address

convertXlfToPhp() public static method

Convert an .xlf file into a PHP language file
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use the Contao\CoreBundle\Config\Loader\XliffFileLoader instead.
public static convertXlfToPhp ( string $strName, string $strLanguage, boolean $blnLoad = false ) : string
$strName string The name of the .xlf file
$strLanguage string The language code
$blnLoad boolean Add the labels to the global language array
return string The PHP code

disableModule() public static method

Disable a back end module
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Composer to add or remove modules.
public static disableModule ( ) : boolean
return boolean True if the module was disabled

enableModule() public static method

Enable a back end module
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Composer to add or remove modules.
public static enableModule ( ) : boolean
return boolean True if the module was enabled

getContainer() public static method

Return the container object
public static getContainer ( ) : Symfony\Component\DependencyInjection\ContainerInterface
return Symfony\Component\DependencyInjection\ContainerInterface The container object

getCountries() public static method

Return the countries as array
public static getCountries ( ) : array
return array An array of country names

getFormattedNumber() public static method

Format a number
public static getFormattedNumber ( mixed $varNumber, integer $intDecimals = 2 ) : mixed
$varNumber mixed An integer or float number
$intDecimals integer The number of decimals to show
return mixed The formatted number

getImageSizes() public static method

Return all image sizes as array
Deprecation: Deprecated since Contao 4.1, to be removed in Contao 5. Use the contao.image.image_sizes service instead.
public static getImageSizes ( ) : array
return array The available image sizes

getIndexFreeRequest() public static method

Return the request string without the script name
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Environment::get("indexFreeRequest") instead.
public static getIndexFreeRequest ( boolean $blnAmpersand = true ) : string
$blnAmpersand boolean If true, ampersands will be encoded
return string The request string

getLanguages() public static method

Return the available languages as array
public static getLanguages ( boolean $blnInstalledOnly = false ) : array
$blnInstalledOnly boolean If true, return only installed languages
return array An array of languages

getMessageTypes() protected method

Return all available message types
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::getTypes() instead.
protected getMessageTypes ( ) : array
return array An array of message types

getMessages() protected method

Return all messages as HTML
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::generate() instead.
protected getMessages ( string $strScope = TL_MODE ) : string
$strScope string An optional message scope
return string The messages HTML markup

getModelClassFromTable() public static method

Compile a Model class name from a table name (e.g. tl_form_field becomes FormFieldModel)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Model::getClassFromTable() instead.
public static getModelClassFromTable ( string $strTable ) : string
$strTable string The table name
return string The model class name

getReadableSize() public static method

Convert a byte value into a human readable format
public static getReadableSize ( integer $intSize, integer $intDecimals = 1 ) : string
$intSize integer The size in bytes
$intDecimals integer The number of decimals to show
return string The human readable size

getReferer() public static method

Return the referer URL and optionally encode ampersands
public static getReferer ( boolean $blnEncodeAmpersands = false, string $strTable = null ) : string
$blnEncodeAmpersands boolean If true, ampersands will be encoded
$strTable string An optional table name
return string The referer URL

getSessionHash() public static method

Return the session hash
public static getSessionHash ( string $strCookie ) : string
$strCookie string The cookie name
return string The session hash

getTimeZones() public static method

Return the timezones as array
public static getTimeZones ( ) : array
return array An array of timezones

idnaDecode() protected method

Decode an internationalized domain name
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Idna::decode() instead.
protected idnaDecode ( string $strDomain ) : string
$strDomain string The domain name
return string The decoded domain name

idnaEncode() protected method

Encode an internationalized domain name
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Idna::encode() instead.
protected idnaEncode ( string $strDomain ) : string
$strDomain string The domain name
return string The encoded domain name

idnaEncodeEmail() protected method

Encode the domain in an e-mail address
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Idna::encodeEmail() instead.
protected idnaEncodeEmail ( string $strEmail ) : string
$strEmail string The e-mail address
return string The encoded e-mail address

idnaEncodeUrl() protected method

Encode the domain in an URL
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Idna::encodeUrl() instead.
protected idnaEncodeUrl ( string $strUrl ) : string
$strUrl string The URL
return string The encoded URL

import() protected method

Import a library and make it accessible by its name or an optional key
protected import ( string $strClass, string $strKey = null, boolean $blnForce = false )
$strClass string The class name
$strKey string An optional key to store the object under
$blnForce boolean If true, existing objects will be overridden

importStatic() public static method

Import a library in non-object context
public static importStatic ( string $strClass, string $strKey = null, boolean $blnForce = false ) : object
$strClass string The class name
$strKey string An optional key to store the object under
$blnForce boolean If true, existing objects will be overridden
return object The imported object

isInstalledLanguage() public static method

Check whether a language is installed
public static isInstalledLanguage ( boolean $strLanguage ) : boolean
$strLanguage boolean The language code
return boolean True if the language is installed

isValidEmailAddress() protected method

Validate an e-mail address
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Validator::isEmail() instead.
protected isValidEmailAddress ( string $strEmail ) : boolean
$strEmail string The e-mail address
return boolean True if it is a valid e-mail address

loadLanguageFile() public static method

Load a set of language files
public static loadLanguageFile ( string $strName, boolean $strLanguage = null, boolean $blnNoCache = false )
$strName string The table name
$strLanguage boolean An optional language code
$blnNoCache boolean If true, the cache will be bypassed

log() public static method

Add a log entry to the database
Deprecation: Deprecated since Contao 4.2, to be removed in Contao 5. Use the logger service instead.
public static log ( string $strText, string $strFunction, string $strCategory )
$strText string The log message
$strFunction string The function name
$strCategory string The category name

parseDate() public static method

Parse a date format string and translate textual representations
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Date::parse() instead.
public static parseDate ( string $strFormat, integer $intTstamp = null ) : string
$strFormat string The date format string
$intTstamp integer An optional timestamp
return string The textual representation of the date

readPhpFileWithoutTags() protected static method

Read the contents of a PHP file, stripping the opening and closing PHP tags
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use the Contao\CoreBundle\Config\Loader\PhpFileLoader instead.
protected static readPhpFileWithoutTags ( string $strName ) : string
$strName string The name of the PHP file
return string The PHP code without the PHP tags

redirect() public static method

Redirect to another page
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Controller::redirect() instead.
public static redirect ( string $strLocation, integer $intStatus = 303 )
$strLocation string The target URL
$intStatus integer The HTTP status code (defaults to 303)

reload() public static method

Reload the current page
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Controller::reload() instead.
public static reload ( )

resetMessages() protected method

Reset the message system
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Message::reset() instead.
protected resetMessages ( )

setContainer() public static method

Set the container object
public static setContainer ( Symfony\Component\DependencyInjection\ContainerInterface $container )
$container Symfony\Component\DependencyInjection\ContainerInterface The container object

setCookie() public static method

Set a cookie
public static setCookie ( string $strName, mixed $varValue, integer $intExpires, string $strPath = null, string $strDomain = null, boolean $blnSecure = false, boolean $blnHttpOnly = false )
$strName string The cookie name
$varValue mixed The cookie value
$intExpires integer The expiration date
$strPath string An optional path
$strDomain string An optional domain name
$blnSecure boolean If true, the secure flag will be set
$blnHttpOnly boolean If true, the http-only flag will be set

splitFriendlyName() public static method

Split a friendly-name e-address and return name and e-mail as array
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use StringUtil::splitFriendlyEmail() instead.
public static splitFriendlyName ( string $strEmail ) : array
$strEmail string A friendly-name e-mail address
return array An array with name and e-mail address

urlEncode() public static method

Urlencode a file path preserving slashes
public static urlEncode ( string $strPath ) : string
$strPath string The file path
return string The encoded file path

Property Details

$arrCache protected property

Cache
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0.
protected array $arrCache
return array

$arrImageSizes protected static property

Available image sizes
protected static array $arrImageSizes
return array

$arrLanguageFiles protected static property

Loaded language files
protected static array $arrLanguageFiles
return array

$arrLanguages protected static property

Available languages
protected static array $arrLanguages
return array

$arrObjects protected property

Default libraries
protected array $arrObjects
return array

$arrStaticObjects protected static property

Static objects
protected static array $arrStaticObjects
return array

$objContainer protected static property

Container
protected static ContainerInterface,Symfony\Component\DependencyInjection $objContainer
return Symfony\Component\DependencyInjection\ContainerInterface