class Env

Properties

static protected bool $putenv

Indicates if the putenv adapter is enabled.

static protected RepositoryInterface|null $repository

The environment repository instance.

static protected AdapterInterface[] $adapters

The adapters used to build the current repository.

static protected Closure[] $customAdapters

The list of custom adapters for loading environment variables.

Methods

static void
enablePutenv()

Enable the putenv adapter.

static void
flushRepository()

Flush the environment repository.

static void
deleteMany(array $keys)

Delete the given environment variable keys from all adapters.

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 array
buildAdapters()

Build the list of additional adapters for the repository.

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

Get the value of an environment variable.

static array
getArray(string $key, array $default = [])

Get a comma-separated environment variable as an array.

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
getOption(string $key)

Get the possible option for this environment variable.

static string
prepareQuotedValue(string $input)

Wrap a string in quotes, choosing double or single quotes.

static string
addSlashesExceptFor(string $value, array $except = [])

Escape a string using addslashes, excluding the specified characters from being escaped.

static int
fileMode(string $path)

Get the basic permission bits for an environment file.

static void
flushState()

Flush all static state.

Details

at line 53
static void enablePutenv()

Enable the putenv adapter.

Boot-only. The setting and cached repository persist in static properties for the worker lifetime and affect every subsequent env lookup.

Return Value

void

at line 71
static void flushRepository()

Flush the environment repository.

Boot or tests only. Clears the worker-wide repository cache; concurrent env lookups may rebuild with different adapter state.

Clears the cached repository so the next getRepository() call creates a fresh instance with a new ImmutableWriter. This is required before reloading env files — the ImmutableWriter tracks which keys it loaded and refuses to overwrite "externally defined" keys. Flushing creates a clean writer that treats all keys as writable.

Return Value

void

at line 89
static void deleteMany(array $keys)

Delete the given environment variable keys from all adapters.

Bypasses the repository's ImmutableWriter and deletes directly from each adapter. This is used during env reload to clear previously loaded values before re-reading the env file.

Also clears the keys from the default adapter superglobals ($_SERVER, $_ENV) which are always present via createWithDefaultAdapters().

Parameters

array $keys

Return Value

void

at line 108
static void disablePutenv()

Disable the putenv adapter.

Boot-only. The setting and cached repository persist in static properties for the worker lifetime and affect every subsequent env lookup.

Return Value

void

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

Register a custom adapter creator Closure.

Boot-only. Custom adapters persist in a static property for the worker lifetime and affect every subsequent env repository build.

Parameters

Closure $callback
string|null $name

Return Value

void

at line 134
static RepositoryInterface getRepository()

Get the environment repository instance.

Return Value

RepositoryInterface

at line 156
static protected array buildAdapters()

Build the list of additional adapters for the repository.

Return Value

array

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

Get the value of an environment variable.

Parameters

string $key
mixed $default

Return Value

mixed

at line 202
static array getArray(string $key, array $default = [])

Get a comma-separated environment variable as an array.

Parameters

string $key
array $default

Return Value

array

Exceptions

InvalidArgumentException

at line 225
static mixed getOrFail(string $key)

Get the value of a required environment variable.

Parameters

string $key

Return Value

mixed

Exceptions

RuntimeException

at line 238
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

at line 262
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

at line 285
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

at line 350
static protected Option getOption(string $key)

Get the possible option for this environment variable.

Parameters

string $key

Return Value

Option

at line 380
static protected string prepareQuotedValue(string $input)

Wrap a string in quotes, choosing double or single quotes.

Parameters

string $input

Return Value

string

at line 392
static protected string addSlashesExceptFor(string $value, array $except = [])

Escape a string using addslashes, excluding the specified characters from being escaped.

Parameters

string $value
array $except

Return Value

string

at line 406
static protected int fileMode(string $path)

Get the basic permission bits for an environment file.

Parameters

string $path

Return Value

int

at line 422
static void flushState()

Flush all static state.

Return Value

void