Skip to content

Instantly share code, notes, and snippets.

@silentworks
Forked from alanpich/example.php
Last active August 29, 2015 14:11
Show Gist options
  • Save silentworks/c70b7c321ef8b85dd499 to your computer and use it in GitHub Desktop.
Save silentworks/c70b7c321ef8b85dd499 to your computer and use it in GitHub Desktop.
<?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');
- /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