hassankhan / config

Config is a lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files
MIT License
972 stars 136 forks source link

Environment support #39

Open gustavohenke opened 9 years ago

gustavohenke commented 9 years ago

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?

hassankhan commented 9 years ago

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?

gustavohenke commented 9 years ago

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.

hassankhan commented 9 years ago

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 commented 8 years ago

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

rauwebieten commented 6 years ago

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

<?php

return [
    'some_config_parameter' => getenv('SOME_ENV_PARAMETER')
];
devnix commented 5 years ago

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)%'