Env
class Env extends Env
Properties
| static protected bool | $putenv | Indicates if the putenv adapter is enabled. |
from Env |
| static protected RepositoryInterface|null | $repository | The environment repository instance. |
from Env |
| static protected AdapterInterface[] | $adapters | The adapters used to build the current repository. |
from Env |
| static protected Closure[] | $customAdapters | The list of custom adapters for loading environment variables. |
from Env |
Methods
Delete the given environment variable keys from all adapters.
Get the value of an environment variable.
Get a comma-separated environment variable as an array.
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.
Determine if environment variable is available.
Set an environment value.
Forget an environment variable.
Forward environment value.
Encode environment variable value.
Details
in
Env 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.
in
Env 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.
in
Env 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().
in
Env 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.
in
Env 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.
in
Env at line 134
static RepositoryInterface
getRepository()
Get the environment repository instance.
in
Env at line 156
static protected array
buildAdapters()
Build the list of additional adapters for the repository.
in
Env at line 189
static mixed
get(string $key, mixed $default = null)
Get the value of an environment variable.
in
Env at line 202
static array
getArray(string $key, array $default = [])
Get a comma-separated environment variable as an array.
in
Env at line 225
static mixed
getOrFail(string $key)
Get the value of a required environment variable.
in
Env at line 238
static void
writeVariables(array $variables, string $pathToFile, bool $overwrite = false)
Write an array of key-value pairs to the environment file.
in
Env 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.
in
Env at line 285
static protected array
addVariableToEnvContents(string $key, mixed $value, array $envLines, bool $overwrite)
Add a variable to the environment file contents.
in
Env at line 350
static protected Option
getOption(string $key)
Get the possible option for this environment variable.
in
Env at line 380
static protected string
prepareQuotedValue(string $input)
Wrap a string in quotes, choosing double or single quotes.
in
Env at line 392
static protected string
addSlashesExceptFor(string $value, array $except = [])
Escape a string using addslashes, excluding the specified characters from being escaped.
in
Env at line 406
static protected int
fileMode(string $path)
Get the basic permission bits for an environment file.
in
Env at line 422
static void
flushState()
Flush all static state.
at line 15
static bool
has(string $key)
Determine if environment variable is available.
at line 23
static void
set(string $key, string $value)
Set an environment value.
at line 31
static bool
forget(string $key)
Forget an environment variable.
at line 39
static mixed
forward(string $key, mixed $default = new UndefinedValue())
Forward environment value.
at line 53
static mixed
encode(mixed $value)
Encode environment variable value.