env-interop / impl
Reference implementations for Env-Interop.
1.0.0-beta2
2026-04-23 03:54 UTC
Requires
- php: >=8.4
- env-interop/interface: 1.x@dev
Requires (Dev)
- pds/composer-script-names: ^1.0
- pds/skeleton: ^1.0
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.0
- pmjones/php-styler: 0.x@dev
This package is auto-updated.
Last update: 2026-04-23 03:58:52 UTC
README
Reference implementations of the Env-Interop interfaces for PHP 8.4+.
Installation
composer require env-interop/impl
Usage
Load a base environment file, with an optional local override:
use EnvInterop\Impl\EnvLoader; new EnvLoader() ->loadEnv('.env.ini') ->loadEnvIfReadable('.env.local.ini');
Read values from the environment:
use EnvInterop\Impl\Env; $env = new Env(); $pdo = new PDO( $env->getEnv('PDO_DSN'), $env->getEnv('PDO_USERNAME'), $env->getEnv('PDO_PASSWORD'), );
Add or replace environment variables:
use EnvInterop\Impl\EnvSetter; $setter = new EnvSetter(); $setter->addEnv('FEATURE_FLAG', true); // only if not already set $setter->setEnv('DEBUG', false); // always replaces; null unsets
Parse environment contents directly (INI syntax, via parse_ini_string()):
use EnvInterop\Impl\EnvParser; $parsed = (new EnvParser())->parseEnv(<<<INI APP_NAME = "example" APP_DEBUG = true INI);
Classes
| Interface | Implementation |
|---|---|
| EnvLoaderService | EnvLoader |
| EnvParserService | EnvParser |
| EnvSetterService | EnvSetter |
| EnvGetter | Env |
| EnvLoaderThrowable | EnvLoaderException |
| EnvParserThrowable | EnvParserException |
| EnvInvalidThrowable | EnvInvalidException |
All classes are in the EnvInterop\Impl namespace.
See the Env-Interop interface package for the full specification.