Environment
class Environment (View source)
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
Extract env vars prior to modification
Restore a backed up or modified list of vars to $globals
Increase the memory limit to the given level if it's currently too low.
Set the maximum allowed value for {@link increaseMemoryLimitTo()}.
No description
Increase the time limit of this script. By default, the time will be unlimited.
Set the maximum allowed value for {@link increaseTimeLimitTo()};
No description
Get value of environment variable
Set environment variable using php.ini syntax.
Set environment variable via $name / $value pair
Returns true if this script is being run from the command line rather than the web server
Details
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.
Only increases up to the maximum defined in {@link setMemoryLimitMax()}, and defaults to the 'memory_limit' setting in the PHP configuration.
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.
static int
getMemoryLimitMax()
static bool
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.
static
setTimeLimitMax(int $timeLimit)
Set the maximum allowed value for {@link increaseTimeLimitTo()};
static int
getTimeLimitMax()
static mixed
getEnv(string $name)
Get value of environment variable
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
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