Skip to content
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

[Dotenv]: search variable values in _ENV first then env file #32943

Open

Conversation

@soufianZantar
Copy link
Contributor

commented Aug 5, 2019

Q A
Branch? 4.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #32595
License MIT
Doc PR symfony/symfony-docs#...

I think we must searhing the value of variables in $_ENV before the .env file to fix this issues.
before this fix Parse method will return the value in .env file and not the value passed in this command composer dump-env prod .

the issue:

In my .env file, I have a variable TEST that depends on the APP_ENV variable like this:

# .env file

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=2eb810c79fba0dd5c029a2fa53bfdb51
###< symfony/framework-bundle ###

TEST=foo_${APP_ENV}

I run composer dump-env dev command to generate my .env.locale.php, everything works fine, the value of my variable TEST is correct.

// .env.locale.php

return array (
  'APP_ENV' => 'dev',
  'TEST' => 'foo_dev',
  'APP_SECRET' => '2eb810c79fba0dd5c029a2fa53bfdb51',
);

Then I run the same command with prod environment (composer dump-env prod), the value of TEST is wrong (it is same as for dev)

// .env.locale.php

return array (
  'APP_ENV' => 'prod',
  'TEST' => 'foo_dev',
  'APP_SECRET' => '2eb810c79fba0dd5c029a2fa53bfdb51',
);

@soufianZantar soufianZantar force-pushed the soufianZantar:dotenv/fix-variable-values-in-command branch from a4b0dfc to d83374d Aug 5, 2019

$test = "APP_ENV=dev\nTEST=foo_\${APP_ENV}";
$values = $dotenv->parse($test);
$this->assertSame('foo_prod', $values['TEST']);

This comment has been minimized.

Copy link
@Kocal

Kocal Aug 5, 2019

Contributor

It should be foo_dev no ?

This comment has been minimized.

Copy link
@soufianZantar

soufianZantar Aug 5, 2019

Author Contributor

No must return the value of $_ENV and not the value of .env file.

when you run the command with prod or other value not the same in .env file the value of TEST is wrong (it is same as in .env file) .

Then I run the same command with prod environment (composer dump-env prod), the value of TEST is wrong (it is same as for dev)

// .env.locale.php

return array (
  'APP_ENV' => 'prod',
  'TEST' => 'foo_dev',
  'APP_SECRET' => '2eb810c79fba0dd5c029a2fa53bfdb51',
);

This comment has been minimized.

Copy link
@Kocal

Kocal Aug 5, 2019

Contributor

Ah, yes my bad. I read it too quickly

@xabbuh xabbuh added this to the 3.4 milestone Aug 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.