config icon indicating copy to clipboard operation
config copied to clipboard

Environment support

Open gustavohenke opened this issue 10 years ago • 6 comments
trafficstars

Hey, I'm a Node.js developer which needs to program an app using PHP for college! So I thought of using this config manager, which is very alike with node-config.

But I want to override a few options with environment variables, because of Heroku, for example. node-config allows me to do this via an special custom-environment-variables configuration.

What do you think of implementing something similar in your amazing project?

gustavohenke avatar Apr 02 '15 11:04 gustavohenke

Hi, I was thinking of some sort of integration with phpdotenv but I'm not quite sure how. Do you have any examples of how you'd like to use it?

hassankhan avatar Apr 04 '15 13:04 hassankhan

That's how it works with that Node module:

custom-environment-variables.yml

db:
  # For Codeship
  username: PG_USER
  password: PG_PASSWORD

  # For Heroku
  url: DATABASE_URL

Then, my db.username and db.password configs are overriden by Codeship env vars, and db.url is overriden by Heroku env vars.

gustavohenke avatar Apr 12 '15 02:04 gustavohenke

This seems a bit overkill for this package, because (AFAIK) we'll have to check the value of each configuration value to see if it matches an environment variable. I hope I'm wrong and there's a better way of doing it.

hassankhan avatar May 08 '15 15:05 hassankhan

Just an update, this can be done in PHP using the dotenv package - still not sure about other file formats though

hassankhan avatar Jan 23 '16 21:01 hassankhan

If you use php as config file, you can load env variables like this:

<?php

return [
    'some_config_parameter' => getenv('SOME_ENV_PARAMETER')
];

rauwebieten avatar Jun 10 '18 08:06 rauwebieten

It could be interesting to have something like Symfony, reading the .env file and filling variables. For example:

db:
  driver: mariadb
  username: '%env(DB_USERNAME)%'
  password: '%env(DB_PASSWORD)%'

devnix avatar Jan 10 '19 07:01 devnix