Description
Symfony version(s) affected
6.1.6
Description
Symfony provides a way to override the default location to look for dotenv files, which is normally the project root:
{
"...": "...",
"extra": {
"...": "...",
"runtime": {
"dotenv_path": "my/custom/path/to/.env"
}
}
}
It also provides a way to list environment variables, using the debug:dotenv
command. However, this command does not recognize the dotenv_path
value set above and continues to look inside the project root.
How to reproduce
mkdir config_dotenv
touch config_dotenv/.env
- Override the default dotenv path in
composer.json
toconfig_dotenv/.env
composer update
./bin/console debug:dotenv
The output is:
Dotenv Variables & Files
========================
Scanned Files (in descending priority)
--------------------------------------
* ⨯ .env.local.php
* ⨯ .env.local.local
* ⨯ .env.local
* ⨯ .env.local
* ⨯ .env
The output should be:
Dotenv Variables & Files
========================
Scanned Files (in descending priority)
--------------------------------------
* ⨯ .env.local.php
* ⨯ .env.local.local
* ⨯ .env.local
* ⨯ .env.local
* ✓ .env
Or instead possibly:
Dotenv Variables & Files
========================
Scanned Files (in descending priority)
--------------------------------------
* ⨯ config_dotenv/.env.local.php
* ⨯ config_dotenv/.env.local.local
* ⨯ config_dotenv/.env.local
* ⨯ config_dotenv/.env.local
* ✓ config_dotenv/.env
Possible Solution
Symfony\Component\Dotenv\Command\DebugCommand::getFilePath()
refers to the ::$projectDirectory
member variable:
symfony/src/Symfony/Component/Dotenv/Command/DebugCommand.php
Lines 164 to 188 in 889f4d6
This member variable is configured in ./src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php
to be the kernel.project_dir
parameter:
symfony/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.php
Lines 141 to 146 in 889f4d6
Instead, the command should receive the dotenv_path
runtime value and use that to locate the .env
files.
Additional Context
No response