PHP Class Contao\Environment

The class returns the environment variables (which are stored in the PHP $_SERVER array) independent of the operating system. Usage: echo Environment::get('scriptName'); echo Environment::get('requestUri');
Exibir arquivo Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrCache array Cache
$objInstance Environment Object instance (Singleton)
$strSapi string The SAPI name

Public Methods

Method Description
__clone ( ) Prevent cloning of the object (Singleton)
__get ( string $strKey ) : string Return an environment variable
__set ( string $strKey, mixed $varValue ) Set an environment variable
get ( string $strKey ) : mixed Return an environment variable
getInstance ( ) : Environment Return the object instance (Singleton)
reset ( ) Reset the internal cache
set ( string $strKey, mixed $varValue ) Set an environment variable

Protected Methods

Method Description
__construct ( ) Prevent direct instantiation (Singleton)
agent ( ) : object Return the operating system and the browser name and version
base ( ) : string Return the URL and path that can be used in a tag
documentRoot ( ) : string Return the document root (e.g. /home/www/user/)
encodeRequestString ( string $strRequest ) : string Encode a request string preserving certain reserved characters
host ( ) : string Return the host name
httpAcceptEncoding ( ) : array Return accepted encoding types as array
httpAcceptLanguage ( ) : array Return the first eight accepted languages as array
httpHost ( ) : string Return the HTTP Host
httpUserAgent ( ) : string Return the user agent as string
httpXForwardedHost ( ) : string Return the HTTP X-Forwarded-Host
indexFreeRequest ( ) : string Return the request string without the index.php fragment
ip ( ) : string Return the real REMOTE_ADDR even if a proxy server is used
isAjaxRequest ( ) : boolean Return true on Ajax requests
path ( ) : string Return the relative path to the base directory (e.g. /path)
phpSelf ( ) : string Alias for scriptName()
queryString ( ) : string Return the query string (e.g. id=2)
relativeRequest ( ) : string Return the request string without the script name (e.g. en/news.html)
request ( ) : string Return the relativ path to the script and include the request (e.g. index.php?id=2)
requestUri ( ) : string Return the request URI [path]?[query] (e.g. /contao/index.php?id=2)
script ( ) : string Return the relativ path to the script (e.g. index.php)
scriptFilename ( ) : string Return the absolute path to the script (e.g. /home/www/html/website/index.php)
scriptName ( ) : string Return the relative path to the script (e.g. /website/index.php)
server ( ) : string Return the SERVER_ADDR
ssl ( ) : boolean Return true if the current page was requested via an SSL connection
uri ( ) : string Return the current URL with path or query string
url ( ) : string Return the current URL without path or query string

Method Details

__clone() final public method

Prevent cloning of the object (Singleton)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. The Environment class is now static.
final public __clone ( )

__construct() protected method

Prevent direct instantiation (Singleton)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. The Environment class is now static.
protected __construct ( )

__get() public method

Return an environment variable
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Environment::get() instead.
public __get ( string $strKey ) : string
$strKey string The variable name
return string The variable value

__set() public method

Set an environment variable
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. Use Environment::set() instead.
public __set ( string $strKey, mixed $varValue )
$strKey string The variable name
$varValue mixed The variable value

agent() protected static method

Return the operating system and the browser name and version
protected static agent ( ) : object
return object The agent information

base() protected static method

Return the URL and path that can be used in a tag
protected static base ( ) : string
return string The base URL

documentRoot() protected static method

Calculated as SCRIPT_FILENAME minus SCRIPT_NAME as some CGI versions and mod-rewrite rules might return an incorrect DOCUMENT_ROOT.
protected static documentRoot ( ) : string
return string The document root

encodeRequestString() protected static method

Encode a request string preserving certain reserved characters
protected static encodeRequestString ( string $strRequest ) : string
$strRequest string The request string
return string The encoded request string

get() public static method

Return an environment variable
public static get ( string $strKey ) : mixed
$strKey string The variable name
return mixed The variable value

getInstance() public static method

Return the object instance (Singleton)
Deprecation: Deprecated since Contao 4.0, to be removed in Contao 5.0. The Environment class is now static.
public static getInstance ( ) : Environment
return Environment The object instance

host() protected static method

Return the host name
protected static host ( ) : string
return string The host name

httpAcceptEncoding() protected static method

Return accepted encoding types as array
protected static httpAcceptEncoding ( ) : array
return array The encoding types array

httpAcceptLanguage() protected static method

Return the first eight accepted languages as array
protected static httpAcceptLanguage ( ) : array
return array The languages array

httpHost() protected static method

Return the HTTP Host
protected static httpHost ( ) : string
return string The host name

httpUserAgent() protected static method

Return the user agent as string
protected static httpUserAgent ( ) : string
return string The user agent string

httpXForwardedHost() protected static method

Return the HTTP X-Forwarded-Host
protected static httpXForwardedHost ( ) : string
return string The name of the X-Forwarded-Host

indexFreeRequest() protected static method

Return the request string without the index.php fragment
protected static indexFreeRequest ( ) : string
return string The request string without the index.php fragment

ip() protected static method

Return the real REMOTE_ADDR even if a proxy server is used
protected static ip ( ) : string
return string The IP address of the client

isAjaxRequest() protected static method

Return true on Ajax requests
protected static isAjaxRequest ( ) : boolean
return boolean True if it is an Ajax request

path() protected static method

Return the relative path to the base directory (e.g. /path)
protected static path ( ) : string
return string The relative path to the installation

phpSelf() protected static method

Alias for scriptName()
protected static phpSelf ( ) : string
return string The script name

queryString() protected static method

Return the query string (e.g. id=2)
protected static queryString ( ) : string
return string The query string

relativeRequest() protected static method

Return the request string without the script name (e.g. en/news.html)
protected static relativeRequest ( ) : string
return string The base URL

request() protected static method

Return the relativ path to the script and include the request (e.g. index.php?id=2)
protected static request ( ) : string
return string The relative path to the script including the request string

requestUri() protected static method

Return the request URI [path]?[query] (e.g. /contao/index.php?id=2)
protected static requestUri ( ) : string
return string The request URI

reset() public static method

Reset the internal cache
public static reset ( )

script() protected static method

Return the relativ path to the script (e.g. index.php)
protected static script ( ) : string
return string The relative path to the script

scriptFilename() protected static method

Return the absolute path to the script (e.g. /home/www/html/website/index.php)
protected static scriptFilename ( ) : string
return string The absolute path to the script

scriptName() protected static method

Return the relative path to the script (e.g. /website/index.php)
protected static scriptName ( ) : string
return string The relative path to the script

server() protected static method

Return the SERVER_ADDR
protected static server ( ) : string
return string The IP address of the server

set() public static method

Set an environment variable
public static set ( string $strKey, mixed $varValue )
$strKey string The variable name
$varValue mixed The variable value

ssl() protected static method

Return true if the current page was requested via an SSL connection
protected static ssl ( ) : boolean
return boolean True if SSL is enabled

uri() protected static method

Return the current URL with path or query string
protected static uri ( ) : string
return string The URL

url() protected static method

Return the current URL without path or query string
protected static url ( ) : string
return string The URL

Property Details

$arrCache protected_oe static_oe property

Cache
protected static array $arrCache
return array

$objInstance protected_oe static_oe property

Object instance (Singleton)
protected static Environment,contao $objInstance
return Environment

$strSapi protected_oe static_oe property

The SAPI name
protected static string $strSapi
return string