Thanks to visit codestin.com
Credit goes to github.com

Skip to content

dump-env always looks for the .env file in the project-root #855

Closed
@predyke

Description

@predyke

Problem

Given the situation that I relocated the env files lookup from root to root/my-custom-folder. It works just fine with configuring runtime variables (dotenv_path) in the composer.json.

"runtime": {
   "dotenv_path": "env/.env",
}

However when I want to dump-env the variables into a php file I run into the problem that the symfony:dump-env command always looks for the project root instead of using the newly configured env folder.

In the DumpEnvCommand class the path is hardcoded.

class Symfony\Flex\Command\DumpEnvCommand

protected function execute(InputInterface $input, OutputInterface $output): int
{
        if ($env = $input->getArgument('env')) {
            $_SERVER['APP_ENV'] = $env;
        }

        $path = $this->options->get('root-dir').'/.env';

Proposed solutions:

  • Either add an optional argument to the command (path) where the lookup path for .env could be overridden (this seems to be the easiest solution)

  • Get the location of the env files from runtime somehow? (haven't done any proof of concept about this yet)

Symfony version: v.6.0.0
Flex version: v1.18.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions