symfony / flex

Composer plugin for Symfony
MIT License
4.15k stars 181 forks source link

`dump-env` command doesn't respect real Env Vars during Expansion. #985

Open sherifabdlnaby opened 1 year ago

sherifabdlnaby commented 1 year ago

Quoting this comment: https://github.com/symfony/flex/pull/507#issuecomment-1021122359

I just ran into this as well. Given this .env file:

FOO=beans
BAR="cool $FOO"

and then in my env exporting another value for FOO:

export FOO=cats

dumping will use the previous value:

$ composer dump-env -- prod
Successfully dumped .env files in .env.local.php

$ cat .env.local.php
<?php

// This file was generated by running "composer dump-env prod"

return array (
  'FOO' => 'beans',
  'BAR' => 'cool beans',
);

this is obviously not what we'd expect.

Our original use case was splitting a DSN connection into strings so we have

TRANSPORT_EVENT_DSN=amqp://${AMQP_USER:-api}:${AMQP_PASS:-api}@${AMQP_HOST:-rabbitmq}:${AMQP_PORT:-5672}/${AMQP_VHOST:-%2f}

after dumping this now has some default value and we can't use it for configuration anymore...