From b0a2dffe11b3d95ac994faf24c1517bac56dc27a Mon Sep 17 00:00:00 2001 From: Simon / Yami Date: Wed, 28 May 2025 11:01:39 +0200 Subject: [PATCH 01/11] [Dotenv] improve documentation for dotenv component --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 2a1cc02..67ff66a 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,15 @@ Getting Started composer require symfony/dotenv ``` +Usage +----- + +> For an .env file with this format: + +```env +YOUR_VARIABLE_NAME=my-string +``` + ```php use Symfony\Component\Dotenv\Dotenv; @@ -25,6 +34,12 @@ $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 From 45a56b57f7c1e5246e093fc154c409659dcb9ed6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 16:08:14 +0200 Subject: [PATCH 02/11] Allow Symfony ^8.0 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 34c4718..fe887ff 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,8 @@ "php": ">=8.2" }, "require-dev": { - "symfony/console": "^6.4|^7.0", - "symfony/process": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0", + "symfony/process": "^6.4|^7.0|^8.0" }, "conflict": { "symfony/console": "<6.4", From 75aa824472f8932d27d1f76b4b9b6d8eb97c1ee9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 17:50:55 +0200 Subject: [PATCH 03/11] Bump Symfony 8 to PHP >= 8.4 --- composer.json | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index fe887ff..0f2f8d4 100644 --- a/composer.json +++ b/composer.json @@ -16,15 +16,11 @@ } ], "require": { - "php": ">=8.2" + "php": ">=8.4" }, "require-dev": { - "symfony/console": "^6.4|^7.0|^8.0", - "symfony/process": "^6.4|^7.0|^8.0" - }, - "conflict": { - "symfony/console": "<6.4", - "symfony/process": "<6.4" + "symfony/console": "^7.4|^8.0", + "symfony/process": "^7.4|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Dotenv\\": "" }, From ebba9fe62f10f9831fb05b52142a7e785001fc0d Mon Sep 17 00:00:00 2001 From: HypeMC Date: Mon, 9 Jun 2025 17:40:54 +0200 Subject: [PATCH 04/11] [Console] Simplify using invokable commands when the component is used standalone --- Tests/Command/DebugCommandTest.php | 6 +++++- Tests/Command/DotenvDumpCommandTest.php | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Tests/Command/DebugCommandTest.php b/Tests/Command/DebugCommandTest.php index 28c0b48..5782829 100644 --- a/Tests/Command/DebugCommandTest.php +++ b/Tests/Command/DebugCommandTest.php @@ -288,7 +288,11 @@ public function testCompletion() $command = new DebugCommand($env, $projectDirectory); $application = new Application(); - $application->add($command); + if (method_exists($application, 'addCommand')) { + $application->addCommand($command); + } else { + $application->add($command); + } $tester = new CommandCompletionTester($application->get('debug:dotenv')); $this->assertSame(['FOO', 'TEST'], $tester->complete([''])); } diff --git a/Tests/Command/DotenvDumpCommandTest.php b/Tests/Command/DotenvDumpCommandTest.php index 44fc304..d2f2dfe 100644 --- a/Tests/Command/DotenvDumpCommandTest.php +++ b/Tests/Command/DotenvDumpCommandTest.php @@ -95,7 +95,12 @@ public function testExecuteTestEnvs() private function createCommand(): CommandTester { $application = new Application(); - $application->add(new DotenvDumpCommand(__DIR__)); + $command = new DotenvDumpCommand(__DIR__); + if (method_exists($application, 'addCommand')) { + $application->addCommand($command); + } else { + $application->add($command); + } return new CommandTester($application->find('dotenv:dump')); } From 46655a0b7ff896f34c16eb53b2f1cd70ca85789d Mon Sep 17 00:00:00 2001 From: HypeMC Date: Fri, 13 Jun 2025 02:20:31 +0200 Subject: [PATCH 05/11] [Console][FrameworkBundle] Remove deprecated `Application::add()` methods --- Tests/Command/DebugCommandTest.php | 6 +----- Tests/Command/DotenvDumpCommandTest.php | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/Tests/Command/DebugCommandTest.php b/Tests/Command/DebugCommandTest.php index 5782829..d95e0eb 100644 --- a/Tests/Command/DebugCommandTest.php +++ b/Tests/Command/DebugCommandTest.php @@ -288,11 +288,7 @@ public function testCompletion() $command = new DebugCommand($env, $projectDirectory); $application = new Application(); - if (method_exists($application, 'addCommand')) { - $application->addCommand($command); - } else { - $application->add($command); - } + $application->addCommand($command); $tester = new CommandCompletionTester($application->get('debug:dotenv')); $this->assertSame(['FOO', 'TEST'], $tester->complete([''])); } diff --git a/Tests/Command/DotenvDumpCommandTest.php b/Tests/Command/DotenvDumpCommandTest.php index d2f2dfe..a31262e 100644 --- a/Tests/Command/DotenvDumpCommandTest.php +++ b/Tests/Command/DotenvDumpCommandTest.php @@ -95,12 +95,7 @@ public function testExecuteTestEnvs() private function createCommand(): CommandTester { $application = new Application(); - $command = new DotenvDumpCommand(__DIR__); - if (method_exists($application, 'addCommand')) { - $application->addCommand($command); - } else { - $application->add($command); - } + $application->addCommand(new DotenvDumpCommand(__DIR__)); return new CommandTester($application->find('dotenv:dump')); } From 7d690cf089e75353e76cb29c272c0641aef5bf03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 20 Jun 2025 11:27:04 +0200 Subject: [PATCH 06/11] [Dotenv] Remove `DebugCommand::$defaultName` and `$defaultDescription` --- Command/DebugCommand.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Command/DebugCommand.php b/Command/DebugCommand.php index 5729b94..9438a69 100644 --- a/Command/DebugCommand.php +++ b/Command/DebugCommand.php @@ -30,16 +30,6 @@ #[AsCommand(name: 'debug:dotenv', description: 'List all dotenv files with variables and values')] final class DebugCommand extends Command { - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultName = 'debug:dotenv'; - - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultDescription = 'List all dotenv files with variables and values'; - public function __construct( private string $kernelEnvironment, private string $projectDirectory, From 05c17644c3c37ff9ede113b7d08a48d2e1f7273a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 20 Jun 2025 12:43:44 +0200 Subject: [PATCH 07/11] Fix CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a587fba..04a18c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +8.0 +--- + + * Remove `$defaultName` and `$defaultDescription` properties from `DebugCommand` command, configuration is done through the `#[AsCommand]` attribute + 7.1 --- From 32f9fa5f4ae0047b3157cf2d88eecd410d99b780 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 8 Jul 2025 11:08:29 +0200 Subject: [PATCH 08/11] Various CS fixes --- Command/DebugCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/DebugCommand.php b/Command/DebugCommand.php index 5729b94..b5b4f51 100644 --- a/Command/DebugCommand.php +++ b/Command/DebugCommand.php @@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $dotenvPath = $this->projectDirectory; if (is_file($composerFile = $this->projectDirectory.'/composer.json')) { - $runtimeConfig = (json_decode(file_get_contents($composerFile), true))['extra']['runtime'] ?? []; + $runtimeConfig = json_decode(file_get_contents($composerFile), true)['extra']['runtime'] ?? []; if (isset($runtimeConfig['dotenv_path'])) { $dotenvPath = $this->projectDirectory.'/'.$runtimeConfig['dotenv_path']; From 61ce0b521c696cc58a7ddbe02226b7c38e34104a Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 9 Oct 2024 11:06:51 +0200 Subject: [PATCH 09/11] run tests using PHPUnit 11.5 --- phpunit.xml.dist | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 461dc69..0cbf618 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -18,7 +19,7 @@ - + ./ @@ -26,5 +27,9 @@ ./Tests ./vendor - + + + + + From 13fdf12a96d16e81df446179fda0df1c1b4cab6e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 31 Jul 2025 14:36:46 +0200 Subject: [PATCH 10/11] replace PHPUnit annotations with attributes --- Tests/Command/DebugCommandTest.php | 13 ++++--------- Tests/DotenvTest.php | 9 +++------ 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Tests/Command/DebugCommandTest.php b/Tests/Command/DebugCommandTest.php index 5782829..2925111 100644 --- a/Tests/Command/DebugCommandTest.php +++ b/Tests/Command/DebugCommandTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Dotenv\Tests\Command; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Application; use Symfony\Component\Console\Helper\FormatterHelper; @@ -22,9 +23,7 @@ class DebugCommandTest extends TestCase { - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testErrorOnUninitializedDotenv() { unset($_SERVER['SYMFONY_DOTENV_VARS']); @@ -38,9 +37,7 @@ public function testErrorOnUninitializedDotenv() $this->assertStringContainsString('[ERROR] Dotenv component is not initialized', $output); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testEmptyDotEnvVarsList() { $_SERVER['SYMFONY_DOTENV_VARS'] = ''; @@ -275,9 +272,7 @@ public function testScenario2InProdEnvWithNameFilterPrefix() $this->assertStringContainsString('TEST 1234 1234 1234 0000', $output); } - /** - * @runInSeparateProcess - */ + #[RunInSeparateProcess] public function testCompletion() { $env = 'prod'; diff --git a/Tests/DotenvTest.php b/Tests/DotenvTest.php index 7f8bd27..69a2e06 100644 --- a/Tests/DotenvTest.php +++ b/Tests/DotenvTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Dotenv\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Dotenv\Dotenv; use Symfony\Component\Dotenv\Exception\FormatException; @@ -18,9 +19,7 @@ class DotenvTest extends TestCase { - /** - * @dataProvider getEnvDataWithFormatErrors - */ + #[DataProvider('getEnvDataWithFormatErrors')] public function testParseWithFormatError($data, $error) { $dotenv = new Dotenv(); @@ -63,9 +62,7 @@ public static function getEnvDataWithFormatErrors() return $tests; } - /** - * @dataProvider getEnvData - */ + #[DataProvider('getEnvData')] public function testParse($data, $expected) { $dotenv = new Dotenv(); From 4a53037ff205b68310ea43d4e999dac54375751c Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 10 Aug 2025 00:28:14 +0200 Subject: [PATCH 11/11] chore: heredoc indentation as of PHP 7.3 https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc --- Command/DebugCommand.php | 10 +++++----- Command/DotenvDumpCommand.php | 14 +++++++------- Tests/Command/DebugCommandTest.php | 22 +++++++++++----------- Tests/Command/DotenvDumpCommandTest.php | 14 +++++++------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Command/DebugCommand.php b/Command/DebugCommand.php index b5b4f51..0b6ed33 100644 --- a/Command/DebugCommand.php +++ b/Command/DebugCommand.php @@ -54,15 +54,15 @@ protected function configure(): void new InputArgument('filter', InputArgument::OPTIONAL, 'The name of an environment variable or a filter.', null, $this->getAvailableVars(...)), ]) ->setHelp(<<<'EOT' -The %command.full_name% command displays all the environment variables configured by dotenv: + The %command.full_name% command displays all the environment variables configured by dotenv: - php %command.full_name% + php %command.full_name% -To get specific variables, specify its full or partial name: + To get specific variables, specify its full or partial name: - php %command.full_name% FOO_BAR + php %command.full_name% FOO_BAR -EOT + EOT ); } diff --git a/Command/DotenvDumpCommand.php b/Command/DotenvDumpCommand.php index 8a367a3..c94b76c 100644 --- a/Command/DotenvDumpCommand.php +++ b/Command/DotenvDumpCommand.php @@ -44,10 +44,10 @@ protected function configure(): void ]) ->addOption('empty', null, InputOption::VALUE_NONE, 'Ignore the content of .env files') ->setHelp(<<<'EOT' -The %command.name% command compiles .env files into a PHP-optimized file called .env.local.php. + The %command.name% command compiles .env files into a PHP-optimized file called .env.local.php. - %command.full_name% -EOT + %command.full_name% + EOT ) ; } @@ -75,13 +75,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $vars = var_export($vars, true); $vars = <<writeln(\sprintf('Successfully dumped .env files in .env.local.php for the %s environment.', $env)); diff --git a/Tests/Command/DebugCommandTest.php b/Tests/Command/DebugCommandTest.php index 2925111..4e48bbe 100644 --- a/Tests/Command/DebugCommandTest.php +++ b/Tests/Command/DebugCommandTest.php @@ -47,17 +47,17 @@ public function testEmptyDotEnvVarsList() $tester = new CommandTester($command); $tester->execute([]); $expectedFormat = <<<'OUTPUT' -%a - ---------- ------- ------------ ------%S - Variable Value .env.local .env%S - ---------- ------- ------------ ------%S - FOO baz bar%S - TEST123 n/a true%S - ---------- ------- ------------ ------%S - - // Note that values might be different between web and CLI.%S -%a -OUTPUT; + %a + ---------- ------- ------------ ------%S + Variable Value .env.local .env%S + ---------- ------- ------------ ------%S + FOO baz bar%S + TEST123 n/a true%S + ---------- ------- ------------ ------%S + + // Note that values might be different between web and CLI.%S + %a + OUTPUT; $this->assertStringMatchesFormat($expectedFormat, $tester->getDisplay()); } diff --git a/Tests/Command/DotenvDumpCommandTest.php b/Tests/Command/DotenvDumpCommandTest.php index d2f2dfe..8fec23b 100644 --- a/Tests/Command/DotenvDumpCommandTest.php +++ b/Tests/Command/DotenvDumpCommandTest.php @@ -21,14 +21,14 @@ class DotenvDumpCommandTest extends TestCase protected function setUp(): void { file_put_contents(__DIR__.'/.env', <<createCommand();