class Dotenv

Manages .env files.

Constants

VARNAME_REGEX

STATE_VARNAME

STATE_VALUE

Methods

void
load(string $path, string ...$paths)

Loads one or several .env files.

void
populate(array $values)

Sets values as environment variables (via putenv, $_ENV, and $_SERVER).

array
parse(string $data, string $path = '.env')

Parses the contents of an .env file.

Details

at line 48
void load(string $path, string ...$paths)

Loads one or several .env files.

Parameters

string $path A file to load
string ...$paths A list of additional files to load

Return Value

void

Exceptions

FormatException when a file has a syntax error
PathException when a file does not exist or is not readable

at line 68
void populate(array $values)

Sets values as environment variables (via putenv, $_ENV, and $_SERVER).

Note that existing environment variables are not overridden.

Parameters

array $values An array of env variables

Return Value

void

at line 108
array parse(string $data, string $path = '.env')

Parses the contents of an .env file.

Parameters

string $data The data to be parsed
string $path The original file name where data where stored (used for more meaningful error messages)

Return Value

array An array of env variables

Exceptions

FormatException when a file has a syntax error