class Env (View source)

Properties

static protected bool $putenv

Indicates if the putenv adapter is enabled.

static protected RepositoryInterface|null $repository

The environment repository instance.

static protected Closure[] $customAdapters

The list of custom adapters for loading environment variables.

Methods

static void
enablePutenv()

Enable the putenv adapter.

static void
disablePutenv()

Disable the putenv adapter.

static void
extend(Closure $callback, string|null $name = null)

Register a custom adapter creator Closure.

static RepositoryInterface
getRepository()

Get the environment repository instance.

static mixed
get(string $key, mixed $default = null)

Get the value of an environment variable.

static mixed
getOrFail(string $key)

Get the value of a required environment variable.

static void
writeVariables(array $variables, string $pathToFile, bool $overwrite = false)

Write an array of key-value pairs to the environment file.

static void
writeVariable(string $key, mixed $value, string $pathToFile, bool $overwrite = false)

Write a single key-value pair to the environment file.

static array
addVariableToEnvContents(string $key, mixed $value, array $envLines, bool $overwrite)

Add a variable to the environment file contents.

static Option|Some
getOption(string $key)

Get the possible option for this environment variable.

Details

static void enablePutenv()

Enable the putenv adapter.

Return Value

void

static void disablePutenv()

Disable the putenv adapter.

Return Value

void

static void extend(Closure $callback, string|null $name = null)

Register a custom adapter creator Closure.

Parameters

Closure $callback
string|null $name

Return Value

void

static RepositoryInterface getRepository()

Get the environment repository instance.

Return Value

RepositoryInterface

static mixed get(string $key, mixed $default = null)

Get the value of an environment variable.

Parameters

string $key
mixed $default

Return Value

mixed

static mixed getOrFail(string $key)

Get the value of a required environment variable.

Parameters

string $key

Return Value

mixed

Exceptions

RuntimeException

static void writeVariables(array $variables, string $pathToFile, bool $overwrite = false)

Write an array of key-value pairs to the environment file.

Parameters

array $variables
string $pathToFile
bool $overwrite

Return Value

void

Exceptions

RuntimeException
FileNotFoundException

static void writeVariable(string $key, mixed $value, string $pathToFile, bool $overwrite = false)

Write a single key-value pair to the environment file.

Parameters

string $key
mixed $value
string $pathToFile
bool $overwrite

Return Value

void

Exceptions

RuntimeException
FileNotFoundException

static protected array addVariableToEnvContents(string $key, mixed $value, array $envLines, bool $overwrite)

Add a variable to the environment file contents.

Parameters

string $key
mixed $value
array $envLines
bool $overwrite

Return Value

array

static protected Option|Some getOption(string $key)

Get the possible option for this environment variable.

Parameters

string $key

Return Value

Option|Some