Environment
The Environment package loads .env files into an in-memory store and exposes two small runtime APIs:
Environmentfor loading and reading environment valuesServerfor reading a captured copy of$_SERVER
In normal application code, the main entry points are the env() and server() helpers.
Package shape
The package is built from these parts:
Quantum\Environment\Environmentselects and loads one.envfileQuantum\Environment\Serverwraps a snapshot of$_SERVERQuantum\Environment\Helpers\env.phpexposesenvironment()andenv()Quantum\Environment\Helpers\server.phpexposesserver(),get_user_ip(), and agetallheaders()fallbackQuantum\Environment\Enums\Envdefines the built-in environment namesQuantum\Environment\Exceptions\EnvExceptionraises package-specific runtime errors
Supported environment names
Quantum\Environment\Enums\Env ships five string constants:
Env::PRODUCTIONEnv::STAGINGEnv::DEVELOPMENTEnv::TESTINGEnv::LOCAL
These constants are convenience values. Environment::load() still accepts any app_env string and uses it directly when building the file name.
What the package is good for
Environment file loading
Environment reads one file from App::getBaseDir():
- production ->
.env - any other
app_envvalue ->.env.<app_env>
Loaded values are stored on the Environment instance in $envContent. Reads after that come from memory, not by re-reading the file.
Request metadata access
Server gives the framework one shared object for request metadata such as URI, method, protocol, host, headers, and client IP.
The object copies $_SERVER in its constructor, so it works as a snapshot, not a live view.
Important runtime constraints
Environment::load()is one-shot; after the first successful load, later calls return immediatelyenv()fails until the environment has been loaded- missing
.envfiles raise an exception instead of returning an empty store updateRow()is disabled unlesssetMutable(true)has been called firstServerreads from its internal array only; later changes to global$_SERVERare not reflected unless the shared instance is rebuilt or mutated throughset()Server::ip()trusts forwarded headers beforeREMOTE_ADDR