Reference implementations for Env-Interop.

Maintainers

Package info

github.com/env-interop/impl

pkg:composer/env-interop/impl

Transparency log

Statistics

Installs: 9

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

1.0.0 2026-07-03 16:21 UTC

This package is auto-updated.

Last update: 2026-07-03 16:21:39 UTC


README

PDS Skeleton PDS Composer Script Names

Reference implementations of the Env-Interop interfaces for PHP 8.4+.

Installation

composer require env-interop/impl

Usage

Load a base environment file (INI format), with an optional local override:

use EnvInterop\Impl\EnvLoader;

new EnvLoader()
    ->loadEnv('.env.ini')
    ->loadEnvIfReadable('.env.local.ini');

loadEnv() and replaceEnv() throw EnvLoaderException if a file cannot be read; the loadEnvIfReadable() and replaceEnvIfReadable() variants suppress that.

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);

parseEnv() throws EnvParserException on a syntax error, or EnvInvalidException if a parsed value is not null or scalar (such as the array produced by key[]= syntax).

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.

The three exception classes extend RuntimeException and implement EnvThrowable from the interface package, so catching that single marker handles any environment error.

See the Env-Interop interface package for the full specification.