PHPackages                             env-interop/impl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. env-interop/impl

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

env-interop/impl
================

Reference implementations for Env-Interop.

1.x-dev(2mo ago)19MITPHPPHP &gt;=8.4CI passing

Since Apr 23Pushed 2mo agoCompare

[ Source](https://github.com/env-interop/impl)[ Packagist](https://packagist.org/packages/env-interop/impl)[ Docs](https://github.com/env-interop/impl)[ RSS](/packages/env-interop-impl/feed)WikiDiscussions 1.x Synced today

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

env-interop/impl
================

[](#env-interopimpl)

[![PDS Skeleton](https://camo.githubusercontent.com/50d01a5094afcc3a827c3cadaec43d23b2a256cb249f5fdd6e5ffdb53ea7971c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d736b656c65746f6e2d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/php-pds/skeleton)[![PDS Composer Script Names](https://camo.githubusercontent.com/0c17df07fd0a51ad878f1de0d4c17ea8e460f2e96ce796c8cd58e6c96ed9c08d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7064732d636f6d706f7365722d2d7363726970742d2d6e616d65732d626c75653f7374796c653d666c61742d737175617265)](https://github.com/php-pds/composer-script-names)

Reference implementations of the [Env-Interop](https://github.com/env-interop/interface) interfaces for PHP 8.4+.

Installation
------------

[](#installation)

```
composer require env-interop/impl

```

Usage
-----

[](#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(
