class Environment

Consolidates access and modification of PHP global variables and settings.

This class should be used sparingly, and only if information cannot be obtained from a current {@link HTTPRequest} object.

Acts as the primary store for environment variables, including those loaded from .env files. Applications should use Environment::getEnv() instead of php's getenv in order to include .env configuration, as the system's actual environment variables are treated immutably.

Methods

static array
getVariables()

Extract env vars prior to modification

static 
setVariables(array $vars)

Restore a backed up or modified list of vars to $globals

static bool
increaseMemoryLimitTo(string|float|int $memoryLimit = -1)

Increase the memory limit to the given level if it's currently too low.

static 
setMemoryLimitMax(string|float $memoryLimit)

Set the maximum allowed value for {@link increaseMemoryLimitTo()}.

static int
getMemoryLimitMax()

No description

static Boolean
increaseTimeLimitTo(int $timeLimit = null)

Increase the time limit of this script. By default, the time will be unlimited.

static 
setTimeLimitMax(int $timeLimit)

Set the maximum allowed value for {@link increaseTimeLimitTo()};

static Int
getTimeLimitMax()

No description

static mixed
getEnv(string $name)

Get value of environment variable

static 
putEnv(string $string)

Set environment variable using php.ini syntax.

static 
setEnv(string $name, string $value)

Set environment variable via $name / $value pair

static bool
isCli()

Returns true if this script is being run from the command line rather than the web server

Details

at line 43
static array getVariables()

Extract env vars prior to modification

Return Value

array List of all super globals

at line 60
static setVariables(array $vars)

Restore a backed up or modified list of vars to $globals

Parameters

array $vars

at line 81
static bool increaseMemoryLimitTo(string|float|int $memoryLimit = -1)

Increase the memory limit to the given level if it's currently too low.

Only increases up to the maximum defined in {@link setMemoryLimitMax()}, and defaults to the 'memory_limit' setting in the PHP configuration.

Parameters

string|float|int $memoryLimit A memory limit string, such as "64M". If omitted, unlimited memory will be set.

Return Value

bool true indicates a successful change, false a denied change.

at line 114
static setMemoryLimitMax(string|float $memoryLimit)

Set the maximum allowed value for {@link increaseMemoryLimitTo()}.

The same result can also be achieved through 'suhosin.memory_limit' if PHP is running with the Suhosin system.

Parameters

string|float $memoryLimit Memory limit string or float value

at line 125
static int getMemoryLimitMax()

Return Value

int Memory limit in bytes

at line 141
static Boolean increaseTimeLimitTo(int $timeLimit = null)

Increase the time limit of this script. By default, the time will be unlimited.

Only works if 'safe_mode' is off in the PHP configuration. Only values up to {@link getTimeLimitMax()} are allowed.

Parameters

int $timeLimit The time limit in seconds. If omitted, no time limit will be set.

Return Value

Boolean TRUE indicates a successful change, FALSE a denied change.

at line 166
static setTimeLimitMax(int $timeLimit)

Set the maximum allowed value for {@link increaseTimeLimitTo()};

Parameters

int $timeLimit Limit in seconds

at line 174
static Int getTimeLimitMax()

Return Value

Int Limit in seconds

at line 185
static mixed getEnv(string $name)

Get value of environment variable

Parameters

string $name

Return Value

mixed Value of the environment variable, or false if not set

at line 206
static putEnv(string $string)

Set environment variable using php.ini syntax.

Acts as a process-isolated version of putenv() Note: This will be parsed via parse_ini_string() which handles quoted values

Parameters

string $string Setting to assign in KEY=VALUE or KEY="VALUE" syntax

at line 221
static setEnv(string $name, string $value)

Set environment variable via $name / $value pair

Parameters

string $name
string $value

at line 231
static bool isCli()

Returns true if this script is being run from the command line rather than the web server

Return Value

bool