Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Predefined constants and global variables

Johan Strydom edited this page Oct 25, 2022 · 3 revisions

By default you will have access to various variables from the PHP super global $_SERVER but the Tsama framework have a few static methods that can also return not just the global variables but also certain logic applied to the super global arrays and the result thereof as well as the arrays for the Tsama global variables such as $_WEB_CONFIG and $_DB_CONFIG and $_THEME_CONFIG.

By default you should be able to access the Server class via the Tsama namespace. Example:

<?php 
namespace Tsama;

$basedir = Server::GetFullBaseDir();

?>

or simply

$basedir = Tsama\Server::GetFullBaseDir();

The following methods are available:

Server::GetProtocol()

Returns either http or https depending on the protocol enabled for your website.

NB: This differs from the super global $_SERVER['SERVER_PROTOCOL']

Server::GetBaseDir()

Returns the base directory of your website installation.

Server::GetDocumentRoot() or Server::GetDocRoot()

Returns the super global $_SERVER['DOCUMENT_ROOT']

Server::GetDomain()

Returns the super global $_SERVER['SERVER_NAME']

Server::GetPort()

Returns the super global $_SERVER['SERVER_PORT']

Server::GetSubDir()

Returns the subdirectory the framework is installed in if different than the root of your website.

This is Tsama specific

Server::GetBaseUrl()

Returns the base url of your website, ending in a / . Example: http://tsama.local/

This is Tsama specific

Server::GetFullBaseDir()

Returns exactly the same value as Server::GetBaseDir()

This is Tsama specific

Server::GetFullSubDir()

Returns a formatted value of the subdirectory. Example: /subdir/

This is Tsama specific

Server::GetRoute()

Returns an array with the current url route.

Example: http://tsama.local/page/carousel will return array( 'page', 'carousel' )

This is Tsama specific

Server::GetService()

Returns the current service being called.

NB: The service is always first item in the route.

Example: http://tsama.local/page/carousel will return page as the service.

This is Tsama specific

Server::GetWebsiteConfig ( [optional] $configName = null )

Returns the $_WEB_CONFIG array or a specific config within the array as an item of an array.

Example:

$siteConf = Server::GetWebsiteConfig();

$siteName = $siteConf["NAME"];

or

$siteConf = Server::GetWebsiteConfig("NAME");

$siteName = $siteConf["NAME"];

This is Tsama specific

Server::GetDatabaseConfig ( [optional] $configName = null )

Returns the $_DB_CONFIG array or a specific config within the array as an item of an array.

Example:

$dbConf = Server::GetDatabaseConfig();

$dbDriver = $dbConf ["Driver"];

or

$dbConf = Server::GetDatabaseConfig("Driver");

$dbDriver = $dbConf ["Driver"];

This is Tsama specific

Server::GetThemeConfig( [optional] $configName = null )

Returns the $_THEME_CONFIG array or a specific config within the array as an item of an array. The array will contain values from the default site theme configured in $_WEB_CONFIG.

Example:

$themeConf= Server::GetThemeConfig();

$themeConf= $dbConf ["BOOTSTRAP_MODE"];

or

$themeConf = Server::GetThemeConfig("BOOTSTRAP_MODE");

$themeConf = $dbConf ["BOOTSTRAP_MODE"];

Server::GetTsamaVersion( )

Returns the Tsama version from $_TSAMA_VERSION

Example:

$version = Server::GetTsamaVersion();

This is Tsama specific

NEXT » Adding content «