Skip to content

Instantly share code, notes, and snippets.

@alanpich
Created December 11, 2014 13:53
Show Gist options
  • Save alanpich/d85fa1075e297e7ea45e to your computer and use it in GitHub Desktop.
Save alanpich/d85fa1075e297e7ea45e to your computer and use it in GitHub Desktop.
<?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