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');
Afficher le fichier Open project: contao/core-bundle Class Usage Examples

Protected Properties

Свойство Type Description
$arrCache array Cache
$objInstance Environment Object instance (Singleton)
$strSapi string The SAPI name

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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 méthode

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 méthode

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
Résultat string The variable value

__set() public méthode

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 méthode

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

base() protected static méthode

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

documentRoot() protected static méthode

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
Résultat string The document root

encodeRequestString() protected static méthode

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

get() public static méthode

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

getInstance() public static méthode

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
Résultat Environment The object instance

host() protected static méthode

Return the host name
protected static host ( ) : string
Résultat string The host name

httpAcceptEncoding() protected static méthode

Return accepted encoding types as array
protected static httpAcceptEncoding ( ) : array
Résultat array The encoding types array

httpAcceptLanguage() protected static méthode

Return the first eight accepted languages as array
protected static httpAcceptLanguage ( ) : array
Résultat array The languages array

httpHost() protected static méthode

Return the HTTP Host
protected static httpHost ( ) : string
Résultat string The host name

httpUserAgent() protected static méthode

Return the user agent as string
protected static httpUserAgent ( ) : string
Résultat string The user agent string

httpXForwardedHost() protected static méthode

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

indexFreeRequest() protected static méthode

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

ip() protected static méthode

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

isAjaxRequest() protected static méthode

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

path() protected static méthode

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

phpSelf() protected static méthode

Alias for scriptName()
protected static phpSelf ( ) : string
Résultat string The script name

queryString() protected static méthode

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

relativeRequest() protected static méthode

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

request() protected static méthode

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

requestUri() protected static méthode

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

reset() public static méthode

Reset the internal cache
public static reset ( )

script() protected static méthode

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

scriptFilename() protected static méthode

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

scriptName() protected static méthode

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

server() protected static méthode

Return the SERVER_ADDR
protected static server ( ) : string
Résultat string The IP address of the server

set() public static méthode

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

ssl() protected static méthode

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

uri() protected static méthode

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

url() protected static méthode

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

Property Details

$arrCache protected_oe static_oe property

Cache
protected static array $arrCache
Résultat array

$objInstance protected_oe static_oe property

Object instance (Singleton)
protected static Environment,contao $objInstance
Résultat Environment

$strSapi protected_oe static_oe property

The SAPI name
protected static string $strSapi
Résultat string