Skip to content

Instantly share code, notes, and snippets.

@dspe
Created October 16, 2014 21:33
Show Gist options
  • Save dspe/1f0186261b88857d417a to your computer and use it in GitHub Desktop.
Save dspe/1f0186261b88857d417a to your computer and use it in GitHub Desktop.
<?php
namespace Game\Config;
use Symfony\Component\Config\Loader\FileLoader;
use Symfony\Component\Yaml\Yaml;
class ConfigLoader extends FileLoader
{
/**
* Loads a resource.
*
* @param mixed $file The resource
* @param string $type The resource type
*/
public function load($file, $type = null)
{
$configValues = Yaml::parse($file);
if (isset($configValues['imports']) ) {
$test = $this->import($_SERVER["DOCUMENT_ROOT"] . '/../src/Test/Resources/config/' . $configValues['imports'][0]['resource']);
unset($configValues['imports']);
$configValues += $test;
}
return $configValues;
}
/**
* Returns true if this class supports the given resource.
*
* @param mixed $resource A resource
* @param string $type The resource type
*
* @return bool true if this class supports the given resource, false otherwise
*/
public function supports($resource, $type = null)
{
return is_string($resource) && 'yml' === pathinfo(
$resource,
PATHINFO_EXTENSION
);
}
}
$configDirectories = $_SERVER["DOCUMENT_ROOT"] . '/../src/Test/Resources/config';
$locator = new FileLocator($configDirectories);
$loaderResolver = new LoaderResolver(array(new ConfigLoader($locator)));
$delegatingLoader = new DelegatingLoader($loaderResolver);
$configPreProcess = $delegatingLoader->load($configDirectories . '/config_' . $environment . '.yml');
var_dump($configPreProcess);
$processor = new Processor();
$configuration = new GlobalConfiguration;
$config = $processor->processConfiguration(
$configuration,
$configPreProcess)
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment