Created
December 11, 2014 13:53
-
-
Save alanpich/d85fa1075e297e7ea45e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use AlanPich\Configurator; | |
use AlanPich\Configurator\FileTypeAdapter; | |
$PROJECT_ROOT = dirname(__FILE__); | |
/////////////////////////////////////////////////////////////////////////////// | |
// Create a configurator | |
// - passing the optional string $basePath as first argument will allow | |
// using relative paths to folders | |
/////////////////////////////////////////////////////////////////////////////// | |
$configurator = new Configurator\Configurator( $PROJECT_ROOT ); | |
/////////////////////////////////////////////////////////////////////////////// | |
// Add the adaptors to load the type of files we want | |
/////////////////////////////////////////////////////////////////////////////// | |
$configurator | |
->addAdaptor( new FileTypeAdapter\PHP() ) | |
->addAdaptor( new FileTypeAdapter\YAML() ); | |
/////////////////////////////////////////////////////////////////////////////// | |
// Add the paths that we want to load from | |
/////////////////////////////////////////////////////////////////////////////// | |
$configurator | |
->addDirectory('/absolute/path/to/folder') | |
->addDirectory('./config/core') | |
->addDirectory('./config/app') | |
->addDirectory('./config/{MY_ENV_VAR}')) | |
// ... or ... | |
$configurator | |
->addDirectories([ | |
'./config/core', | |
'./config/app', | |
'./config/{MY_ENV_VAR' | |
]) | |
/////////////////////////////////////////////////////////////////////////////// | |
// Load the config files | |
/////////////////////////////////////////////////////////////////////////////// | |
$configurator->load(); | |
/////////////////////////////////////////////////////////////////////////////// | |
// Access the data | |
/////////////////////////////////////////////////////////////////////////////// | |
$foo = $configurator['my']['settings']['namespace']; | |
$bar = $configurator->my->settings->namespace; | |
$baz = $configurator('my.settings.namespace'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment