mirror of
https://github.com/symfony/dotenv.git
synced 2026-03-23 23:52:14 +01:00
v8.0.7
* 7.4: [WebProfilerBundle] Cleanup whitespace [Validator] Regex bypass when match is false with too big input gracefully handle the kernel.runtime_mode.web parameter missing [JsonStreamer] Fix missing generator for shared types in self-referencing objects [Mailer] Rewrite "rebanded" to "re-branded" [DependencyInjection] Handle Stringable for string-typed arguments in CheckTypeDeclarationsPass [DependencyInjection] Fix TypeError when using a custom container base class with typed $parameterBag [Dotenv] Defer variable and command expansion to account for overrides from subsequent .env files Bump Symfony version to 7.4.7 Update VERSION for 7.4.6 Update CHANGELOG for 7.4.6 Bump Symfony version to 6.4.35 Update VERSION for 6.4.34 Update CONTRIBUTORS for 6.4.34 Update CHANGELOG for 6.4.34
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%