Search by

small / env

small

Small Env parses .env files and resolves environment variables for standalone PHP projects.

1.1.0 2026-10-11 13:22 UTC

This package is auto-updated.

Last update: 2026-10-11 13:22:54 UTC


README

Code coverage   Tests status

About

small-env reads variables from the operating system and from .env files, with quoted values, multiline values and variable substitution. It is a standalone PHP package: no Swoole or OpenSwoole extension is required.

Install

Requires PHP 8.3 or newer.

composer require small/env

Usage

Read an environment variable

use Small\Env\Env;

$env = new Env();
$value = $env->get('APP_ENV');

Values not already loaded from a file are read from the process environment. Missing variables raise Small\Env\Exception\MissingException.

Read a dotenv file

use Small\Env\Env;

$env = (new Env())->parseFile(__DIR__ . '/.env');
echo $env->get('MY_VAR');

Override a parsed value with the system environment

$env->parseFile(__DIR__ . '/.env');
$env->grabFromSystem('MY_VAR');
echo $env->get('MY_VAR');

Development and tests

The testing workflow mirrors small/swoole-patterns but uses only standard PHP 8.4 with Pest and PCOV, without Swoole, databases or message brokers.

bash bin/tests      # build the PHP image and run Pest + coverage
bash bin/phpstan    # run PHPStan at maximum strictness
bash bin/composer --version

Alternatively:

docker compose build app
docker compose run --rm app composer test

The test process refreshes tests/img/tests-badge.png and tests/img/coverage-badge.png using the same badge layout as Small Swoole Patterns. The test job requires 100% executable-line coverage; failures or incomplete coverage prevent green badges.

Releases

Tags follow Semantic Versioning, starting from the imported 1.0.0. Run from a clean main checkout:

bash bin/release --dev
bash bin/release --patch
bash bin/release --minor
bash bin/release --major

The release script runs the tests, updates .version, creates a release commit, pushes it and publishes an annotated tag. GitLab CI runs checks/tests on commits and produces/uploads the release archive on version tags.

License

Copyright 2026 - Sébastien Kus. Distributed under the MIT license.