Environment data

Environment data covers post back data (from $_POST), query parameters from the URL (from $_GET), server information (from $_SERVER), session data (from $_SESSION), cookie data (from $_COOKIE) and more. The class may be used to properly access these data. If data is read directly from ie the $_POST array, and the given key has not been specified, an E_Notice will be thrown, if the server has been configured to display such messages. This will not happen when using the SMEnvironment class.

// will throw E_Notice if name is not specified in URL
$name = $_GET["name"];

// Will simply return NULL, if name is not set. No E_Notice is thrown.
$name = SMEnvironment::GetQueryValue("name")
SMEnvironment class

Function Return type Description
::GetEnvironmentValue($key:string)
String
Get server information from $_SERVER array.
::GetEnvironmentData()
String[]
Get $_SERVER array.
::GetPostValue($key:string)
String
Get post back value from $_POST array.
::GetPostData()
String[]
Get $_POST array.
::GetQueryValue($key:string)
String
Get URL parameter from $_GET array.
::GetQueryData()
String[]
Get $_GET array.
::GetRequestValue($key:string)
String
Get post back value or URL parameter from $_REQUEST array. Use GetPostValue($key:string) or GetQueryValue($key:string) if possible, to make it clear from where data originates.
::GetRequestData()
String[]
Get $_REQUEST array
::GetSessionValue($key:string)
String
Get session value from $_SESSION array.
::SetSessionValue($data:SMKeyValue)

DEPRECATED - use ::SetSession($key:string, $value:string) instead.
Store session value in $_SESSION array. Example: SMEnvironment::SetSessionValue(new SMKeyValue("key", "value")); Remember to use unique names for sessions (ie prefix with name of extension).
::DestroySessionValue($key:string)

DEPRECATED - use ::DestroySession($key:string) instead.
Remove session value from $_SESSION array.
::SetSession($key:string, $value:string)   Store session value in $_SESSION array. Example: SMEnvironment::SetSessionValue("key", "value"); Remember to use unique names for sessions (ie prefix with name of extension).
::DestroySession($key:string)   Remove session value from $_SESSION array.
::GetSessionData()
String[]
Get $_SESSION array.
::GetCookieValue($key:string)
String
Get cookie value from $_COOKIE array.
::SetCookieValue($data:SMKeyValue)

DEPRECATED - use ::SetCookie($key:string, $value:string) instead.
Set cookie value in $_COOKIE array. Example: SMEnvironment::SetCookieValue(new SMKeyValue("key", "value")); Remember to use unique names for cookies (ie prefix with name of extension).
::DestroyCookieValue($key:string)

DEPRECATED - use ::DestroyCookie($key:string) instead.
Remove cookie value from $_COOKIE array.
::SetCookie($key:string, $value:string)   Set cookie value in $_COOKIE array. Example: SMEnvironment::SetCookieValue("key", "value"); Remember to use unique names for cookies (ie prefix with name of extension).
::DestroyCookie($key:string)   Remove cookie value from $_COOKIE array.
::GetCookieData()
String[]
Get $_COOKIE array.
::GetExternalUrl()
String
Returns the URL on which Sitemagic CMS is installed, ie http://sitemagic.org/dev
::GetMetaData()
SMKeyValueCollection Get Sitemagic CMS meta data. Indexes: Title, Description, Author, Company, Website, Email, Version, Dependencies, Notes.
::GetFilesDirectory()
String
Returns path to writable files directory relative to the root of the Sitemagic CMS installation. Usage: SMEnvironment::GetFilesDirectory() . "/images/test.png".
::GetExtensionsDirectory() String Returns path to extensions directory relative to the root of the Sitemagic CMS installation. Usage: SMEnvironment::GetExtensionDirectory() . "/data/feed.xml".
::GetDataDirectory() String Returns path to data directory relative to the root of the Sitemagic CMS installation. Usage: SMEnvironment::GetDataDirectory() . "/feed.xml".
::GetRootDirectory() String Returns path to the Sitemagic CMS root directory. Usage: SMEnvironment::GetRootDirectory() . "/metadata.xml".
::GetTemplatesDirectory() String Returns path to templates directory relative to the root of the Sitemagic CMS installation. Usage: SMEnvironment::GetTemplatesDirectory() . "/MyTemplate/index.html".