bytic / dotenv
bytic dotenv wrapper
Requires
- php: ^7.2.5 || ^8.0
- bytic/utility: ^1.0
- symfony/console: ^5.0 || ^6.0 || ^7.0 || ^8.0
- symfony/dotenv: ^5.0 || ^6.0 || ^7.0 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.19 || ^3.0
- phpunit/phpunit: ^8.5 || ^9.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-22 20:39:29 UTC
README
A backwards-compatible wrapper for Symfony Dotenv.
Requirements
PHP 7.2.5 or later and Symfony Dotenv and Console 5, 6, 7 or 8. Each Symfony major has its own PHP requirements; in particular, Symfony 8 requires PHP 8.4 or later. Composer selects compatible versions for your PHP version.
Usage
Implement environmentPathGeneric() on your application and use the existing HasEnviroment trait:
use ByTIC\Dotenv\HasEnv\HasEnviroment; use ByTIC\Dotenv\Support\DotenvLoader; class Application { use HasEnviroment; protected function environmentPathGeneric() { return __DIR__; } } $app = new Application(); DotenvLoader::safeLoad($app);
By default, the loader starts with .env in the application's environment path. Use useEnvironmentPath($path) and loadEnvironmentFrom($file) to configure it. If an application reports runningInConsole(), an existing file suffixed with the --env option takes precedence; otherwise, an existing file suffixed with APP_ENV is selected. If neither exists, the configured file is used. Symfony's bootEnv() then loads the selected file and its related environment files. Existing environment variables are not overridden. Invalid environment files are reported to stderr and terminate the process with exit code 1, as before.
Development
Run vendor/bin/phpunit after installing dependencies. The PHP-CS-Fixer configuration uses the Symfony ruleset as a starting point for gradual style migration; run vendor/bin/php-cs-fixer fix --dry-run --diff to review changes. Run the fixer with a PHP version compatible with the minimum supported PHP version, so it does not introduce unsupported syntax.