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

Question about .env and $_ENV #11

Closed
pgaultier opened this issue Aug 28, 2018 · 7 comments
Closed

Question about .env and $_ENV #11

pgaultier opened this issue Aug 28, 2018 · 7 comments

Comments

@pgaultier
Copy link

Hello,

I'm using the plugin, but when I create some config with such code :

    'request' => [
        'enableCookieValidation' => false,
        'cookieValidationKey' => $_ENV['YII_COOKIE_VALIDATION_KEY'],
    ],

it is compiled as

  array (
    '__class' => 'yii\\web\\Request',
    'enableCookieValidation' => false,
    'cookieValidationKey' => 'qdslkfjlkezhtazehtklezjsqhdflkjqshdfkljsqsfg873dsfqgs32345Y67',
  ),

while I was expecting something like this

  array (
    '__class' => 'yii\\web\\Request',
    'enableCookieValidation' => false,
    'cookieValidationKey' => $_ENV['YII_COOKIE_VALIDATION_KEY'],
  ),

am I doing something wrong ?

@SilverFire
Copy link
Member

It is an expected behavior. Variables that can be resolved during compilation will be saved as values.

Do you have any problems with it?

@pgaultier
Copy link
Author

Well, I was reading the generated file and it starts with :

$baseDir = dirname(dirname(dirname(__DIR__)));

$_ENV = array_merge((array) require __DIR__ . '/dotenv.php', (array) $_ENV);

require_once $baseDir . '/common/config/defines.php';
require_once $baseDir . '/vendor/yiisoft/yii-core/config/defines.php';
...

as the $_ENV var is repopulated for each request, I thought the $_ENV could be used.

Anyway, in my case (I'm using flynn for some apps), it is easy to update an environment variable while it's not to re-run composer du. Being able to use runtime $_ENV would save me some time.

It would be great to be able to tell your plugin if we want to "expand" the $_ENV in configs or not.

@SilverFire
Copy link
Member

@hiqsol

@hiqsol
Copy link
Member

hiqsol commented Aug 28, 2018

It can be done but it's not easy.
I hope I'll find time for it later.

@pgaultier
Copy link
Author

@hiqsol Ok, thank you for your quick answer

rodion-k added a commit to rodion-k/composer-config-plugin that referenced this issue Sep 6, 2018
@schmunk42
Copy link

There should be an option like "evaluate-env": false to accomplish that.

@loveorigami
Copy link
Contributor

May be it is will be usefull
https://github.com/helhum/dotenv-connector

@hiqsol hiqsol closed this as completed Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants