lib/ezutils/classes/ezsys.php
File containing the eZSys class.
Portions are modifications of patches by Andreas Böckler and Francis Nart
- Copyright
- Copyright (C) 1999-2011 eZ Systems AS. All rights reserved.
- License
- eZ Business Use License Agreement Version 2.0
- Package
- lib
- Version
- 4.6.0
\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


array
$AccessPath= ''
The access path of the current site view, associated array of associated arrays.
On first level key is 'siteaccess' and 'path' to distinguish between siteaccess and general path. On second level you have (string)'name' and (array)'url', where url is the path and name is the name of the source (used to match siteaccess in {@link eZSys::indexFile()} for RemoveSiteAccessIfDefaultAccess matching) .
- Type
- array


string
$FileSystemType= ''
The type of filesystem, is either win32 or unix. This often used to determine OS specific paths.
- Type
- string


string
$LineSeparator= ''
The line separator used in files, "\n" / "\n\r" / "\r"
- Type
- string


array
$Params= ''
Holds server variables as read automatically or provided by unit tests Only used by init functionality as other calls will need to use live data direclty from globals.
- Type
- array


string
$QueryString= ''
Query string for the current request In the form of "?param1=value1¶m2=value2
- Type
- string


string
$RequestURI= ''
The uri which is used for parsing module/view information from, may differ from $_SERVER['REQUEST_URI']
- Type
- string


\stringt
$ShellEscapeCharacter= ''
The character to be used in shell escaping, this character is OS specific
- Type
- \stringt


\eZSys|null
$instance= 'null'
Holds eZSys instance
null
Details- Type
- \eZSys | null
Methods


__construct(
array $serverParams
=
array()
)
:
void
Initialize the object with settings taken from the current script run.
Name | Type | Description |
---|---|---|
$serverParams | array | For unit testing use, see first few lines for content |


__get(
string $propertyName
)
:
mixed
Magic function to get access readonly properties (protected)
Name | Type | Description |
---|---|---|
$propertyName | string |
Type | Description |
---|---|
mixed |
Exception | Description |
---|---|
\ezcBasePropertyNotFoundException |


addAccessPath(
array | string $path, string $name
=
'undefined', bool $siteaccess
=
true
)
:
void
Appends the access path (parts of url that identifies siteaccess), used by {@link eZSys::indexFile()} NOTE: Does not make sense to use for siteaccess, as you would want to clear current path and set new one normally, so preferably use {@link eZSys::setAccessPath()} in this case.
Name | Type | Description |
---|---|---|
$path | array | string | |
$name | string | An identifer of the name of the path provided {@link $AccessPath} |
$siteaccess | bool | Hints if path is siteaccess related or not, needed in case subsequesnt code suddenly changes siteaccess and needs to clear siteaccess scope |


attribute(
string $attr
)
:
null | string
Returns the attribute value for $attr or null if the attribute does not exist
Name | Type | Description |
---|---|---|
$attr | string |
Type | Description |
---|---|
null | string |


attributes(
)
:
array
Make sure that certain attribute keys are available in $this->Attributes
Type | Description |
---|---|
array |


backupFilename(
)
:
string
Returns the backup filename for this platform
Possible values: .bak (win32), ~ (unix, mac)
Type | Description |
---|---|
string |


cacheDirectory(
)
:
string
Returns the current cache directory.
Type | Description |
---|---|
string |


clearAccessPath(
bool $siteaccess
=
true
)
:
void
Clears the access path, used by {@link eZSys::indexFile()}
Name | Type | Description |
---|---|---|
$siteaccess | bool |


clientIP(
)
:
string
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['HTTP_X_FORWARDED_FOR]
Type | Description |
---|---|
string |


createShellArgument(
string $argumentText, array $replaceList
)
:
string
Replaces % elements in $argumentText using $replaceList, and also properly escape the argument
Name | Type | Description |
---|---|---|
$argumentText | string | |
$replaceList | array |
Type | Description |
---|---|
string |


envSeparator(
)
:
string
Returns the string used as environment separator on the current system
Type | Description |
---|---|
string |


environmentVariable(
string $variableName, bool $quiet
=
false
)
:
null | string
Returns an environment variable or null if it is not available
If the variable is not available, trigger an error message
Name | Type | Description |
---|---|---|
$variableName | string | |
$quiet | bool |
Type | Description |
---|---|
null | string |


escapeShellArgument(
string $argument
)
:
string
Returns an escaped string to be used as a shell argument
Name | Type | Description |
---|---|---|
$argument | string |
Type | Description |
---|---|
string |


ezcrc32(
$string
)
:
int | string
A wrapper for PHP's crc32 function. Returns the crc32 polynomial as unsigned int
Name | Type | Description |
---|---|---|
$string |
Type | Description |
---|---|
int | string |


fileSeparator(
)
:
string
Returns the string used as the file separator on the current system
Type | Description |
---|---|
string |


filesystemType(
)
:
string
Returns the filesystem type
Possible values: win32, unix
Type | Description |
---|---|
string |


getValidwwwDir(
string $phpSelf, string $scriptFileName, string $index
)
:
string | null | false
Generate wwwdir from phpSelf if valid accoring to scriptFileName and return null if invalid and false if there is no index in phpSelf
Name | Type | Description |
---|---|---|
$phpSelf | string | |
$scriptFileName | string | |
$index | string |
Type | Description |
---|---|
string | null | false | String in form 'path/path2' if valid, null if not and false if $index is not part of phpself |


globBrace(
string $pattern, int $flags
=
0
)
:
array
Wraps around the built-in glob() function to provide same functionality for systems (e.g Solaris) that does not support GLOB_BRACE.
Name | Type | Description |
---|---|---|
$pattern | string | |
$flags | int |
Type | Description |
---|---|
array |


hasAttribute(
string $attr
)
:
bool
Checks if the attribute $attr is set.
Name | Type | Description |
---|---|---|
$attr | string |
Type | Description |
---|---|
bool |


hasEnvironmentVariable(
string $variableName
)
:
bool
Checks if an environment variable is available
Name | Type | Description |
---|---|---|
$variableName | string |
Type | Description |
---|---|
bool |


hostname(
)
:
string
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.
Type | Description |
---|---|
string |


indexDir(
bool $withAccessList
=
true
)
:
string
Returns the filepath for the index file.
Name | Type | Description |
---|---|---|
$withAccessList | bool |
Type | Description |
---|---|
string |


indexFile(
bool $withAccessPath
=
true
)
:
string
Returns the filepath for the index file with the access path appended
Name | Type | Description |
---|---|---|
$withAccessPath | bool |
Type | Description |
---|---|
string |


indexFileName(
)
:
string
Returns the filepath for the index file
Type | Description |
---|---|
string |


init(
string $index
=
'index.php', bool $forceVirtualHost
=
null
)
:
void
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.
Name | Type | Description |
---|---|---|
$index | string | The current index file, needed for virtual host mode detection. |
$forceVirtualHost | bool | Virtual host mode is normally autodetected, but if not this can be forced by setting this to true. |


instance(
)
:
\eZSys
Returns a shared instance of the eZSys class
Type | Description |
---|---|
\eZSys |


isDebugEnabled(
)
:
bool
Returns true if debugging of internals is enabled, this will display which server variables are read.
Set the option with setIsDebugEnabled().
Type | Description |
---|---|
bool |
- Deprecated
- Since 4.5, not used


isPHPVersionSufficient(
array $requiredVersion
)
:
bool
Checks if the given version is greater than or equal to the current PHP version
Usage:
eZSys::isPHPVersionSufficient( array( 4, 1, 0 ) );
Name | Type | Description |
---|---|---|
$requiredVersion | array | Must be an array with version number |
Type | Description |
---|---|
bool |
- Deprecated
- Since 4.5


isSSLNow(
)
:
bool
Determines if SSL is enabled and protocol HTTPS is used.
Type | Description |
---|---|
bool |


isShellExecution(
)
:
bool
Determines if the current process has been started from the web or the shell
Type | Description |
---|---|
bool |


lineSeparator(
)
:
string
Returns the string used as line separator on the current system
Type | Description |
---|---|
string |


magickQuotes(
)
:
null
Should return true when magick quotes are enabled, but instead return null.
Type | Description |
---|---|
null |
- Deprecated
- since 4.5


mergeArgumentElements(
array $argumentElements
)
:
string
Merges an argument list created by eZSys::splitArgumentIntoElements() back into a text string
Name | Type | Description |
---|---|---|
$argumentElements | array |
Type | Description |
---|---|
string |


osName(
)
:
string | bool
Returns the current OS name or false if it can not be determined.
Possible values: windows, linux, freebsd, darwin
Type | Description |
---|---|
string | bool |


osType(
)
:
string
Returns the OS type
Possible values: win32, unix
Type | Description |
---|---|
string |


path(
bool $quiet
=
false
)
:
mixed | null
Returns the server's path string
Name | Type | Description |
---|---|---|
$quiet | bool |
Type | Description |
---|---|
mixed | null |


phpVersion(
)
:
array
Returns the PHP version as an array with the version elements.
Type | Description |
---|---|
array |
- Deprecated
- Since 4.5


phpVersionText(
)
:
string
The PHP version as text.
Type | Description |
---|---|
string |
- Deprecated
- Since 4.5, use PHP_VERSION


queryString(
)
:
string
Returns the query string for the current request.
?param1=value1¶m2=value2
Type | Description |
---|---|
string |


removeMagicQuotes(
)
:
void
Removes magic quotes
- Deprecated
- Since 4.5, magic quotes setting has been deprecated in PHP 5.3


requestURI(
)
:
string
Returns the URI used for parsing modules, views and parameters
May differ from $_SERVER['REQUEST_URI'].
Type | Description |
---|---|
string |


rootDir(
)
:
string | null
Returns the absolute path to the eZ Publish root directory
Type | Description |
---|---|
string | null |


serverPort(
)
:
int
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'
Type | Description |
---|---|
int |


serverProtocol(
)
:
string
Returns the current server protocol depending on if SSL is enabled or not.
Type | Description |
---|---|
string |


serverURL(
)
:
string
Returns the server URL (protocol and hostname and port)
Type | Description |
---|---|
string |


serverVariable(
string $variableName, bool $quiet
=
false
)
:
mixed | null
Returns the value of $_SERVER[$variableName] if it is set.
If it isn't set, trigger an error message if $quiet is false
Name | Type | Description |
---|---|---|
$variableName | string | |
$quiet | bool |
Type | Description |
---|---|
mixed | null |


setAccessPath(
array $path
=
array(), string $name
=
'undefined', bool $siteaccess
=
true
)
:
void
Set access path (parts of url that identifies siteaccess), used by {@link eZSys::indexFile()}
Name | Type | Description |
---|---|---|
$path | array | |
$name | string | An identifer of the name of the path provided {@link $AccessPath} |
$siteaccess | bool | Hints if path is siteaccess related or not, needed in case subsequesnt code suddenly changes siteaccess and needs to clear siteaccess scope |


setEnvironmentVariable(
string $variableName, mixed $variableValue
)
:
void
Sets an environment variable for the current process/page view
Name | Type | Description |
---|---|---|
$variableName | string | |
$variableValue | mixed |


setInstance(
\eZSys $instance
=
null
)
:
void
Sets eZSys instance or clears it if left undefined.
Name | Type | Description |
---|---|---|
$instance | \eZSys |


setIsDebugEnabled(
bool $debug
)
:
void
Sets whether internal debugging is enabled or not.
Name | Type | Description |
---|---|---|
$debug | bool |
- Deprecated
- Since 4.5, has not effect anymore


setServerVariable(
string $variableName, mixed $variableValue
)
:
void
Sets a server variable in the global array $_SERVER
Note: Variables are only set for the current process/page view
Name | Type | Description |
---|---|---|
$variableName | string | |
$variableValue | mixed |


simulateGlobBrace(
$filenames
)
:
array
Expands a list of filenames like GLOB_BRACE does.
GLOB_BRACE is non POSIX and only available in GNU glibc. This is needed to support operating systems like Solars.
Name | Type | Description |
---|---|---|
$filenames |
Type | Description |
---|---|
array |


siteDir(
)
:
string
Returns the path to where all the code resides.
Type | Description |
---|---|
string |


splitArgumentIntoElements(
string $argumentText
)
:
array
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()
Name | Type | Description |
---|---|---|
$argumentText | string |
Type | Description |
---|---|
array |


storageDirectory(
)
:
string
Returns the current storage directory
Type | Description |
---|---|
string |


varDirectory(
)
:
string
Returns the path of the current var directory
Type | Description |
---|---|
string |