class Environment

Allow accessing environment variables

Methods

static bool
has(string $key)

Determine if an environment variable exists.

static string
get(string $key)

Get a specific environment variable.

static Option
tryGet(string $key)

Try to get an environment value

static string
getOr(string $key, string $default)

Get a specific environment variable, or a default value if it doesn't exist.

Details

at line 20
static bool has(string $key)

Determine if an environment variable exists.

Parameters

string $key

The environment variable name

Return Value

bool

at line 31
static string get(string $key)

Get a specific environment variable.

Parameters

string $key

The environment variable name

Return Value

string

Exceptions

InvalidArgumentException

at line 46
static Option tryGet(string $key)

Try to get an environment value

Parameters

string $key

The key of the environment value to get

Return Value

Option

Some if found, None if not found

at line 64
static string getOr(string $key, string $default)

Get a specific environment variable, or a default value if it doesn't exist.

If the variable is set with an empty string value, this method will consider it as a legitimate value and so return an empty string.

Parameters

string $key

The environment variable name

string $default

The default value to use when not existing

Return Value

string

The environment variable, or the default value.