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.
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.
Get the basic permission bits for an environment file.
Flush all static state.
Details
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.
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.
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().
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.
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.
at line 143
static RepositoryInterface
getRepository()
Get the environment repository instance.
at line 165
static protected array
buildAdapters()
Build the list of additional adapters for the repository.
at line 203
static mixed
get(string $key, mixed $default = null)
Get the value of an environment variable.
at line 216
static array
getArray(string $key, array $default = [])
Get a comma-separated environment variable as an array.
at line 240
static mixed
getOrFail(string $key)
Get the value of a required environment variable.
at line 253
static void
writeVariables(array $variables, string $pathToFile, bool $overwrite = false)
Write an array of key-value pairs to the environment file.
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.
at line 300
static protected array
addVariableToEnvContents(string $key, mixed $value, array $envLines, bool $overwrite)
Add a variable to the environment file contents.
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.
at line 400
static protected Option
getOption(string $key)
Get the possible option for this environment variable.
at line 430
static protected string
prepareQuotedValue(string $input)
Wrap a string in quotes, choosing double or single quotes.
at line 442
static protected string
addSlashesExceptFor(string $value, array $except = [])
Escape a string using addslashes, excluding the specified characters from being escaped.
at line 456
static protected int
fileMode(string $path)
Get the basic permission bits for an environment file.
at line 472
static void
flushState()
Flush all static state.