dkm / dotenv-autoload
Auto-loads .env then .env.local at Composer autoload time. No plugin, no config.
Requires
- php: >=8.1
- composer-runtime-api: ^2.1
- symfony/dotenv: ^6.4 || ^7.0
This package is auto-updated.
Last update: 2026-06-23 12:23:52 UTC
README
Auto-loads .env then .env.local into the environment at Composer autoload
time. It replaces helhum/dotenv-connector + a custom adapter package with a
single plain library — no Composer plugin, no extra config, no
allow-plugins entry, no generated include file.
Install
composer require dkm/dotenv-autoload
That's the whole integration. The package's autoload.files entry runs
src/load.php whenever vendor/autoload.php is loaded.
Behaviour
- Loads
<project-root>/.env, then<project-root>/.env.local..envholds shared defaults;.env.localcarries per-instance overrides. - Project root is resolved via
Composer\InstalledVersions::getRootPackage(), so it works even when this package is installed as a symlinked path repo (wheredirname(__DIR__, N)would point intopackages/...). - Uses Symfony Dotenv
load(): a variable already set in the real environment (or in.env) is not overwritten by.env.local. SetDOTENV_OVERRIDE=1to switch tooverload()so.env.localwins. - Skips entirely when
APP_ENVis already set in the environment.
Boundary (important)
Env vars are exposed when vendor/autoload.php is loaded — i.e. on web requests
and in CLI subprocesses (e.g. the typo3 binary invoked from Composer
scripts). They are not exposed inline inside the running Composer process.
So this is safe for:
- application runtime, and
- Composer scripts that shell out to a binary (
typo3 ...).
It is not sufficient for:
- a Composer plugin, or
- an inline PHP-callback Composer script (
"Vendor\\Class::method"),
that reads these env vars during composer install/update. If you ever add one
of those and it needs .env values, keep helhum/dotenv-connector for that
project instead.