dkm/dotenv-autoload

Auto-loads .env then .env.local at Composer autoload time. No plugin, no config.

Maintainers

Package info

gitlab.com/dkm-extensions/dotenv-autoload

Issues

pkg:composer/dkm/dotenv-autoload

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.0 2026-06-22 11:55 UTC

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. .env holds shared defaults; .env.local carries 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 (where dirname(__DIR__, N) would point into packages/...).
  • Uses Symfony Dotenv load(): a variable already set in the real environment (or in .env) is not overwritten by .env.local. Set DOTENV_OVERRIDE=1 to switch to overload() so .env.local wins.
  • Skips entirely when APP_ENV is 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.