eZ Publish Community Project (Legacy Stack) 2013.4
Class

eZSys

class eZSys

Easy access to various system settings

The system is checked to see whether a virtualhost-less setup is used and sets the appropriate variables which can be fetched with siteDir(), wwwDir() and indexFile(). It also detects file and environment separators, fetch them with fileSeparator() and envSeparator().

// Run the init in the index file eZSys::init( 'index.php', $ini->variable( 'SiteAccessSettings', 'ForceVirtualHost' ) === 'true' ); echo eZSys::indexFile(); echo eZSys::wwwDir();

Properties

string $LineSeparator The line separator used in files, "\n" / "\n\r" / "\r"
string $FileSeparator The directory separator used for files, '/' or '\'
string $EnvSeparator The list separator used for env variables (':' or ';')
string $RootDir The absolute path to the root directory.
string $SiteDir The system path to where all the code resides
string $WWWDir The relative directory path of the vhless setup
string $IndexFile The index file name (eg: 'index.php')
string $RequestURI The uri which is used for parsing module/view information from, may differ from $SERVER['REQUESTURI']
string $FileSystemType The type of filesystem, is either win32 or unix.
stringt $ShellEscapeCharacter The character to be used in shell escaping, this character is OS specific
string $OSType The type of OS, is either win32, mac or unix.

Methods

__construct(array $serverParams = array())

Initialize the object with settings taken from the current script run.

static string osType()

Returns the OS type

static string|bool osName()

Returns the current OS name or false if it can not be determined.

static string filesystemType()

Returns the filesystem type

static string fileSeparator()

Returns the string used as the file separator on the current system

static bool isShellExecution()

Determines if the current process has been started from the web or the shell

static string escapeShellArgument(string $argument)

Returns an escaped string to be used as a shell argument

static string createShellArgument(string $argumentText, array $replaceList)

Replaces % elements in $argumentText using $replaceList, and also properly escape the argument

static array splitArgumentIntoElements(string $argumentText)

Splits $argumentText on boundaries formed by one or more spaces and save them into an array of separate arguments.

static string mergeArgumentElements(array $argumentElements)

Merges an argument list created by eZSys::splitArgumentIntoElements() back into a text string

static string backupFilename()

Returns the backup filename for this platform

static string lineSeparator()

Returns the string used as line separator on the current system

static string envSeparator()

Returns the string used as environment separator on the current system

static string varDirectory()

Returns the path of the current var directory

static string storageDirectory()

Returns the current storage directory

static string cacheDirectory()

Returns the current cache directory.

static string|null rootDir()

Returns the absolute path to the eZ Publish root directory

static string siteDir()

Returns the path to where all the code resides.

static string wwwDir()

Returns the relative directory path of the vhless setup.

static string indexDir(bool $withAccessList = true)

Returns the filepath for the index file.

static string queryString()

Returns the query string for the current request.

static string indexFile(bool $withAccessPath = true)

Returns the filepath for the index file with the access path appended

static string indexFileName()

Returns the filepath for the index file

static string hostname()

Returns the current hostname.

static string clientIP()

Returns the client IP whether he's behind a proxy or not

static bool isSSLNow()

Determines if SSL is enabled and protocol HTTPS is used.

static string serverProtocol()

Returns the current server protocol depending on if SSL is enabled or not.

static string serverURL()

Returns the server URL (protocol and hostname and port)

static int serverPort()

Returns the server port or 80 as default if the server port can not be retrieved from the hostname or the server variable 'SERVER_PORT'

static mixed|null serverVariable(string $variableName, bool $quiet = false)

Returns the value of $_SERVER[$variableName] if it is set.

static void setServerVariable(string $variableName, mixed $variableValue)

Sets a server variable in the global array $_SERVER

static mixed|null path(bool $quiet = false)

Returns the server's path string

static null|string environmentVariable(string $variableName, bool $quiet = false)

Returns an environment variable or null if it is not available

static bool hasEnvironmentVariable(string $variableName)

Checks if an environment variable is available

static void setEnvironmentVariable(string $variableName, mixed $variableValue)

Sets an environment variable for the current process/page view

array attributes()

Make sure that certain attribute keys are available in $this->Attributes

bool hasAttribute(string $attr)

Checks if the attribute $attr is set.

null|string attribute(string $attr)

Returns the attribute value for $attr or null if the attribute does not exist

mixed __get(string $propertyName)

Magic function to get access readonly properties (protected)

bool __isset(string $propertyName)

Magic function to see if readonly properties (protected) exists

static  init(string $index = 'index.php', bool $forceVirtualHost = null)

Initializes some variables according to some global PHP values.

static string requestURI()

Returns the URI used for parsing modules, views and parameters

static eZSys instance()

Returns a shared instance of the eZSys class

static  setInstance(eZSys $instance = null)

Sets eZSys instance or clears it if left undefined.

static int|string ezcrc32($string $string)

A wrapper for PHP's crc32 function.

static string protocolSchema()

Returns the schema of the request.

static array globBrace(string $pattern, int $flags)

Wraps around the built-in glob() function to provide same functionality for systems (e.g Solaris) that does not support GLOB_BRACE.

Details

at line 151
public __construct(array $serverParams = array())

Initialize the object with settings taken from the current script run.

Parameters

array $serverParams For unit testing use, see first few lines for content

at line 217
static public string osType()

Returns the OS type

Possible values: win32, unix

Return Value

string

at line 229
static public string|bool osName()

Returns the current OS name or false if it can not be determined.

Possible values: windows, linux, freebsd, darwin

Return Value

string|bool

at line 241
static public string filesystemType()

Returns the filesystem type

Possible values: win32, unix

Return Value

string

at line 251
static public string fileSeparator()

Returns the string used as the file separator on the current system

Return Value

string

at line 261
static public bool isShellExecution()

Determines if the current process has been started from the web or the shell

Return Value

bool

at line 286
static public string escapeShellArgument(string $argument)

Returns an escaped string to be used as a shell argument

Parameters

string $argument

Return Value

string

at line 310
static public string createShellArgument(string $argumentText, array $replaceList)

Replaces % elements in $argumentText using $replaceList, and also properly escape the argument

Parameters

string $argumentText
array $replaceList

Return Value

string

at line 347
static public array splitArgumentIntoElements(string $argumentText)

Splits $argumentText on boundaries formed by one or more spaces and save them into an array of separate arguments.

The number of spaces between to arguments is inserted as an integer value between two argument values.

Example: $list = splitArgumentIntoElements( "-geometry 100x100" ); var_dump( $list ); // Output: array( "-geometry", 1, "100x100" );

You can then easily modify the elements separately and create the argument text with eZSys::mergeArgumentElements()

Parameters

string $argumentText

Return Value

array

at line 446
static public string mergeArgumentElements(array $argumentElements)

Merges an argument list created by eZSys::splitArgumentIntoElements() back into a text string

Parameters

array $argumentElements

Return Value

string

at line 471
static public string backupFilename()

Returns the backup filename for this platform

Possible values: .bak (win32), ~ (unix, mac)

Return Value

string

at line 481
static public string lineSeparator()

Returns the string used as line separator on the current system

Return Value

string

at line 491
static public string envSeparator()

Returns the string used as environment separator on the current system

Return Value

string

at line 501
static public string varDirectory()

Returns the path of the current var directory

Return Value

string

at line 512
static public string storageDirectory()

Returns the current storage directory

Return Value

string

at line 525
static public string cacheDirectory()

Returns the current cache directory.

Return Value

string

at line 545
static public string|null rootDir()

Returns the absolute path to the eZ Publish root directory

Return Value

string|null

at line 570
static public string siteDir()

Returns the path to where all the code resides.

Return Value

string

at line 580
static public string wwwDir()

Returns the relative directory path of the vhless setup.

Return Value

string

at line 591
static public string indexDir(bool $withAccessList = true)

Returns the filepath for the index file.

Parameters

bool $withAccessList

Return Value

string

at line 605
static public string queryString()

Returns the query string for the current request.

?param1=value1&param2=value2

Return Value

string

at line 616
static public string indexFile(bool $withAccessPath = true)

Returns the filepath for the index file with the access path appended

Parameters

bool $withAccessPath

Return Value

string

at line 661
static public string indexFileName()

Returns the filepath for the index file

Return Value

string

at line 674
static public string hostname()

Returns the current hostname.

First tries to use X-Forward-Host before it goes on to use host in header, if none of them exists fallback to use host part of site.ini[SiteSettings]|SiteURL setting.

Return Value

string

at line 712
static public string clientIP()

Returns the client IP whether he's behind a proxy or not

Use [HTTPHeaderSettings].ClientIpByCustomHTTPHeader in site.ini if you want to use a custom http header such as X-Forwarded-For

Note: X-Forwarded-For is transformed by PHP into $SERVER['HTTPXFORWARDEDFOR]

eZDebug calls in this method should be avoided as there is a risk of infinite recurstion due to IP check (http://issues.ez.no/19045

Return Value

string

at line 742
static public bool isSSLNow()

Determines if SSL is enabled and protocol HTTPS is used.

Return Value

bool

at line 777
static public string serverProtocol()

Returns the current server protocol depending on if SSL is enabled or not.

Return Value

string

at line 790
static public string serverURL()

Returns the server URL (protocol and hostname and port)

Return Value

string

at line 821
static public int serverPort()

Returns the server port or 80 as default if the server port can not be retrieved from the hostname or the server variable 'SERVER_PORT'

Return Value

int

at line 854
static public mixed|null serverVariable(string $variableName, bool $quiet = false)

Returns the value of $_SERVER[$variableName] if it is set.

If it isn't set, trigger an error message if $quiet is false

Parameters

string $variableName
bool $quiet

Return Value

mixed|null

at line 876
static public void setServerVariable(string $variableName, mixed $variableValue)

Sets a server variable in the global array $_SERVER

Note: Variables are only set for the current process/page view

Parameters

string $variableName
mixed $variableValue

Return Value

void

at line 887
static public mixed|null path(bool $quiet = false)

Returns the server's path string

Parameters

bool $quiet

Return Value

mixed|null

at line 901
static public null|string environmentVariable(string $variableName, bool $quiet = false)

Returns an environment variable or null if it is not available

If the variable is not available, trigger an error message

Parameters

string $variableName
bool $quiet

Return Value

null|string

at line 920
static public bool hasEnvironmentVariable(string $variableName)

Checks if an environment variable is available

Parameters

string $variableName

Return Value

bool

at line 932
static public void setEnvironmentVariable(string $variableName, mixed $variableValue)

Sets an environment variable for the current process/page view

Parameters

string $variableName
mixed $variableValue

Return Value

void

at line 942
public array attributes()

Make sure that certain attribute keys are available in $this->Attributes

Return Value

array

at line 959
public bool hasAttribute(string $attr)

Checks if the attribute $attr is set.

Parameters

string $attr

Return Value

bool

at line 970
public null|string attribute(string $attr)

Returns the attribute value for $attr or null if the attribute does not exist

Parameters

string $attr

Return Value

null|string

at line 1072
public mixed __get(string $propertyName)

Magic function to get access readonly properties (protected)

Parameters

string $propertyName

Return Value

mixed

Exceptions

ezcBasePropertyNotFoundException

at line 1087
public bool __isset(string $propertyName)

Magic function to see if readonly properties (protected) exists

Parameters

string $propertyName Option name to check for.

Return Value

bool Whether the option exists.

at line 1101
static public init(string $index = 'index.php', bool $forceVirtualHost = null)

Initializes some variables according to some global PHP values.

This function should be called once in the index file with the parameters stated in the parameter list.

Parameters

string $index The current index file, needed for virtual host mode detection.
bool $forceVirtualHost Virtual host mode is normally autodetected, but if not this can be forced by setting this to true.

at line 1250
static public string requestURI()

Returns the URI used for parsing modules, views and parameters

May differ from $SERVER['REQUESTURI'].

Return Value

string

at line 1260
static public eZSys instance()

Returns a shared instance of the eZSys class

Return Value

eZSys

at line 1274
static public setInstance(eZSys $instance = null)

Sets eZSys instance or clears it if left undefined.

Parameters

eZSys $instance

at line 1285
static public int|string ezcrc32($string $string)

A wrapper for PHP's crc32 function.

Returns the crc32 polynomial as unsigned int

Parameters

$string $string

Return Value

int|string

at line 1302
static public string protocolSchema()

Returns the schema of the request.

Return Value

string

at line 1321
static public array globBrace(string $pattern, int $flags)

Wraps around the built-in glob() function to provide same functionality for systems (e.g Solaris) that does not support GLOB_BRACE.

Parameters

string $pattern
int $flags

Return Value

array