Skip to content

[RFC][DotEnv] Move Flex dump-env command to DotEnv component #32093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fbourigault opened this issue Jun 19, 2019 · 9 comments
Closed

[RFC][DotEnv] Move Flex dump-env command to DotEnv component #32093

fbourigault opened this issue Jun 19, 2019 · 9 comments
Labels
Dotenv RFC RFC = Request For Comments (proposals about features that you want to be discussed) Stalled

Comments

@fbourigault
Copy link
Contributor

fbourigault commented Jun 19, 2019

I would suggest to move the dump-env command from Flex to the DotEnv component as a standalone executable.

By doing so, anybody using the DotEnv standalone component would be able to use the dumped environment feature.

Also the symfony:dump-env could proxy to the component script to keep the current behavior and DX.

WDYT?

@javiereguiluz javiereguiluz added Dotenv RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Jun 19, 2019
@apfelbox
Copy link
Contributor

Doesn't this create a circular dependency in case you changed something in your Dotfile?

As the symfony command would itself use symfony for dumping the vars, it might run into problems. By being a composer command it is decoupled from Symfony, which is a good thing (in this case).

A solution would be to add the command as standalone executable.

@fbourigault
Copy link
Contributor Author

A solution would be to add the command as standalone executable.

That's what I'm thinking about. Just forgot to write it down!

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 26, 2019

The core of the code we're talking about would look like this (copy-pasted from https://github.com/symfony/flex/blob/master/src/Command/DumpEnvCommand.php):

function dumpEnv(string $path, string $env)
{
        $globalsBackup = [$_SERVER, $_ENV];
        unset($_SERVER['APP_ENV']);
        $_ENV = ['APP_ENV' => $env];
        $_SERVER['SYMFONY_DOTENV_VARS'] = implode(',', array_keys($_SERVER));
        putenv('SYMFONY_DOTENV_VARS='.$_SERVER['SYMFONY_DOTENV_VARS']);

        try {
            $this->loadEnv($path);
            unset($_ENV['SYMFONY_DOTENV_VARS']);
            $vars = $_ENV;
        } finally {
            list($_SERVER, $_ENV) = $globalsBackup;
        }

        $vars = var_export($vars, true);
        $vars = <<<EOF
<?php

// This file was generated by dumping the "$env" env

return $vars;

EOF;
        file_put_contents($path.'.local.php', $vars, LOCK_EX);
}

I wouldn't make this a command in the component.
Maybe a method on Dotenv? Someone that cares would need to make it happen :)

@nicolas-grekas
Copy link
Member

@fbourigault up for a PR? Otherwise we might close I think.

@fbourigault
Copy link
Contributor Author

It’s still on my todo list ;)

@craigh
Copy link

craigh commented Mar 17, 2020

this is a good idea. The dump-env shouldn't be dependent on flex please.

@stof
Copy link
Member

stof commented Mar 17, 2020

Well, the component might expose its own script vendor/bin/dump-env rather than hooking into bin/console if that causes an issue with circular references.

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@fbourigault
Copy link
Contributor Author

This is implemented since Symfony 5.4 🎉 (see #42610)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dotenv RFC RFC = Request For Comments (proposals about features that you want to be discussed) Stalled
Projects
None yet
Development

No branches or pull requests

7 participants