2017 © Pedro Peláez
 

library config-loader

Gives access to structured config values in files or environment variables

image

earthit/config-loader

Gives access to structured config values in files or environment variables

  • Thursday, October 19, 2017
  • by TOGoS
  • Repository
  • 5 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHP Config Loader

Gives access to structured configuration variables stored in JSON files and/or environment variables., (*1)

Example

Let's say config/database.json looks like:, (*2)

{
    "driver": "postgres",
    "host": "db.example.org",
    "dbname": "OVERRIDE ME PLZ THX",
    "notes": [
        "This is the greatest database configuration.",
        "My brother Bob said so."
    ]
}

And we're going to run our PHP script with these environment variables:, (*3)

database_dbname=bobco
otherthing_json='{"foo":"bar","baz","quux"}'
otherthing_foo="jk actually not bar"

And then we have a script like:, (*4)

$loader = new EarthIT_ConfigLoader( 'database', $_ENV )
echo "Database: "; var_export($loader->get('database'));
echo "Other thing: "; var_export($loader->get('otherthing'));

Would output something like:, (*5)

Database: array (
  driver => 'postgres',
  host => 'db.example.org',
  dbname => 'bobco',
  notes => array (
    'This is the greatest database configuration.',
    'My brother Bob said so.'
  )
)
Other thing: array (
  'foo' => 'jk actually not bar',
  'baz' => 'quux'
)

Overrides

Variables are merged in the following order, with later steps 'overriding' the values from earlier steps:, (*6)

  • JSON files
  • files in subdirectories (e.g. 'foo/bar.json' can override 'bar' from 'foo.json')
  • JSON-encoded environment variables
  • Leaf environment variables

If an array value overrides another array value, they are merged instead of replacing the old one., (*7)

Environment variable names

  • Underscores have special meaning, so if you have a variable foo_bar_baz=42, it's going to show up when fetched from the ConfigLoader as array('foo'=>array('bar'=>array('baz'=>42))), (*8)

  • The postfix json also has special meaning. It means that the value of the variable named by the part before "_json" will be determined by JSON-decoding this environment variable's value., (*9)

The Versions

19/10 2017

dev-master

9999999-dev

Gives access to structured config values in files or environment variables

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires

19/10 2017

1.0.0

1.0.0.0

Gives access to structured config values in files or environment variables

  Sources   Download

MIT

The Requires

  • php >=5.2

 

The Development Requires