Env
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
Enable the putenv adapter.
Flush the environment repository.
Delete the given environment variable keys from all adapters.
Disable the putenv adapter.
Get the environment repository instance.
Build the list of additional adapters for the repository.
Get the value of an environment variable.
Get a comma-separated environment variable as an array.
Get the value of a required environment variable.
Write an array of key-value pairs to the environment file.
Write a single key-value pair to the environment file.
Add a variable to the environment file contents.
Get the possible option for this environment variable.
Wrap a string in quotes, choosing double or single quotes.
Escape a string using addslashes, excluding the specified characters from being escaped.
Get the basic permission bits for an environment file.
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.
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.
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().
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.
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.
at line 134
static RepositoryInterface
getRepository()
Get the environment repository instance.
at line 156
static protected array
buildAdapters()
Build the list of additional adapters for the repository.
at line 189
static mixed
get(string $key, mixed $default = null)
Get the value of an environment variable.
at line 202
static array
getArray(string $key, array $default = [])
Get a comma-separated environment variable as an array.
at line 225
static mixed
getOrFail(string $key)
Get the value of a required environment variable.
at line 238
static void
writeVariables(array $variables, string $pathToFile, bool $overwrite = false)
Write an array of key-value pairs to the environment file.
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.
at line 285
static protected array
addVariableToEnvContents(string $key, mixed $value, array $envLines, bool $overwrite)
Add a variable to the environment file contents.
at line 350
static protected Option
getOption(string $key)
Get the possible option for this environment variable.
at line 380
static protected string
prepareQuotedValue(string $input)
Wrap a string in quotes, choosing double or single quotes.
at line 392
static protected string
addSlashesExceptFor(string $value, array $except = [])
Escape a string using addslashes, excluding the specified characters from being escaped.
at line 406
static protected int
fileMode(string $path)
Get the basic permission bits for an environment file.
at line 422
static void
flushState()
Flush all static state.