-
-
Save silentworks/c70b7c321ef8b85dd499 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__); | |
define('ENVIRONMENT', 'development'); | |
/////////////////////////////////////////////////////////////////////////////// | |
// Create a configurator | |
// - passing the optional string $basePath as first argument will allow | |
// using relative paths to folders | |
/////////////////////////////////////////////////////////////////////////////// | |
$configurator = new Configurator\Configurator( $PROJECT_ROOT, ENVIRONMENT ); | |
/////////////////////////////////////////////////////////////////////////////// | |
// 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('./core/config') | |
->addDirectory('./app/config') | |
// ... or ... | |
$configurator | |
->addDirectories([ | |
'./core/config', | |
'./app/config', | |
]) | |
/////////////////////////////////////////////////////////////////////////////// | |
// Load the config files | |
/////////////////////////////////////////////////////////////////////////////// | |
$configurator->load(); | |
/////////////////////////////////////////////////////////////////////////////// | |
// Access the data | |
/////////////////////////////////////////////////////////////////////////////// | |
$foo = $configurator['my']['settings']['namespace']; | |
$bar = $configurator->my->settings->namespace; | |
$baz = $configurator('my.settings.namespace'); |
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
- /app | |
- /config | |
content_type.php | |
database.php | |
- /development | |
database.php | |
// Since my environment is set to development, when getting database config, | |
// it will pull from the `/app/config/database.php` first and then override it with '/app/config/development/database.php'. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment