Created
October 16, 2014 21:33
-
-
Save dspe/1f0186261b88857d417a 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 | |
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 | |
); | |
} | |
} |
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
$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