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.
Parse the environment file lines into entries with the line span of each entry.
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 58
static void
enablePutenv()
Enable the putenv adapter.
The setting and cached repository persist in static properties for the worker lifetime and affect every subsequent env lookup.
in
Env at line 77
static void
flushRepository()
Flush the environment repository.
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 96
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 115
static void
disablePutenv()
Disable the putenv adapter.
The setting and cached repository persist in static properties for the worker lifetime and affect every subsequent env lookup.
in
Env at line 128
static void
extend(Closure $callback, string|null $name = null)
Register a custom adapter creator Closure.
Custom adapters persist in a static property for the worker lifetime and affect every subsequent env repository build.
in
Env at line 143
static RepositoryInterface
getRepository()
Get the environment repository instance.
in
Env at line 165
static protected array
buildAdapters()
Build the list of additional adapters for the repository.
in
Env at line 203
static mixed
get(string $key, mixed $default = null)
Get the value of an environment variable.
in
Env at line 216
static array
getArray(string $key, array $default = [])
Get a comma-separated environment variable as an array.
in
Env at line 240
static mixed
getOrFail(string $key)
Get the value of a required environment variable.
in
Env at line 253
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 277
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 300
static protected array
addVariableToEnvContents(string $key, mixed $value, array $envLines, bool $overwrite)
Add a variable to the environment file contents.
in
Env at line 371
static protected array
parseEnvEntries(array $envLines)
Parse the environment file lines into entries with the line span of each entry.
Multiline values are grouped by the dotenv parser, so text inside a value is never mistaken for an assignment. Entries the parser rejects are skipped.
in
Env at line 400
static protected Option
getOption(string $key)
Get the possible option for this environment variable.
in
Env at line 430
static protected string
prepareQuotedValue(string $input)
Wrap a string in quotes, choosing double or single quotes.
in
Env at line 442
static protected string
addSlashesExceptFor(string $value, array $except = [])
Escape a string using addslashes, excluding the specified characters from being escaped.
in
Env at line 456
static protected int
fileMode(string $path)
Get the basic permission bits for an environment file.
in
Env at line 472
static void
flushState()
Flush all static state.
at line 15
static bool
has(string $key)
Determine if environment variable is available.
at line 24
static void
set(string $key, string $value)
Set an environment value.
at line 32
static bool
forget(string $key)
Forget an environment variable.
at line 40
static mixed
forward(string $key, mixed $default = new UndefinedValue())
Forward environment value.
at line 55
static mixed
encode(mixed $value)
Encode environment variable value.