mirror of
https://github.com/symfony/dotenv.git
synced 2026-03-23 23:52:14 +01:00
8.1
* 7.4: [VarDumper] Wrong dumper output for Accept: aplication/json requests [HttpKernel] Reset router locale to default when finishing main request Only decrement pendingRequests when it's more than zero [Dotenv] Fix self-referencing variables with defaults and env key resolution during deferred expansion Improve Bulgarian translations in validators.bg.xlf [Cache] Fix ChainAdapter ignoring item expiry when propagating to earlier adapters [Form] Fix typed property initialization in ValidatorExtension [Messenger] Fix duplicate pending messages in Redis transport with batch handlers Fix deprecation notices for "@method" annotations when implementing interfaces directly
Dotenv Component
Symfony Dotenv parses .env files to make environment variables stored in them
accessible via $_SERVER or $_ENV.
Getting Started
composer require symfony/dotenv
Usage
For an .env file with this format:
YOUR_VARIABLE_NAME=my-string
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
// you can also load several files
$dotenv->load(__DIR__.'/.env', __DIR__.'/.env.dev');
// overwrites existing env variables
$dotenv->overload(__DIR__.'/.env');
// loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV
$dotenv->loadEnv(__DIR__.'/.env');
// Usage with $_ENV
$envVariable = $_ENV['YOUR_VARIABLE_NAME'];
// Usage with $_SERVER
$envVariable = $_SERVER['YOUR_VARIABLE_NAME'];
Resources
Languages
PHP
100%