Coder1
Coder1

Reputation: 13321

Some env vars in .env are not available in debug:conter --env-vars

My .env file has the following entries, but FOO is not listed when I run bin/console debug:container --env-vars. Note however that $_ENV['FOO'] exists when I dump the variable.

FOO=1
AUTH0_CLIENT_ID=clientid
AUTH0_CLIENT_SECRET=secret
AUTH0_DOMAIN=myapp.us.auth0.com

What determines if an env var defined in .env will be available in the container?

Upvotes: 3

Views: 1756

Answers (1)

Cerad
Cerad

Reputation: 48893

Not really sure if this is worthy of an answer but I suppose it might help.

The Symfony .env files are really just one possible sources of $_ENV variables. There are lots of other env variables floating around and of course in production, you might not use .env at all.

So rather than save access to all env variables, the Symfony configuration system only saves those that are actually used. So in this case:

# config/services.yaml
parameters:
    foo: '%env(resolve:FOO)%'

Will result in:

bin/console debug:container --env-vars
  APP_SECRET          n/a                "84dc6de50e6f2f7af3db3f78f886840f"                                      
  DATABASE_URL        n/a                "mysql://db_user:[email protected]:3306/db_name?serverVersion=5.7"  
  FOO                 n/a                "1"                                                                     
  MAILER_DSN          n/a                n/a                                                                     
  VAR_DUMPER_SERVER   "127.0.0.1:9912"   n/a     

For a fresh 5.1 project.

Off-topic but vaguely interesting to me at least, the above command also generates a warning

 [WARNING] The following variables are missing:
 * MAILER_DSN

MAILER_DSN is commented out in the default .env file. So I guess it is possible to use env values during configuration even if none are defined at compile time. Good way to check for spelling errors I guess.

Upvotes: 2

Related Questions