Trismegiste\Mondrian\Config\Helper::getConfig PHP Method

getConfig() public method

Read the config
public getConfig ( string $dir ) : array
$dir string filepath to the package directory
return array the full config
    public function getConfig($dir)
    {
        // load
        try {
            // all this stuff is not really necessary but this component is kewl
            // and I want to use it.
            // A better configuration handling => better programing
            $delegatingLoader = new DelegatingLoader(new LoaderResolver(array(new Loader())));
            $config = $delegatingLoader->load($dir);
        } catch (FileLoaderLoadException $e) {
            $config = array();
        }
        // validates
        $processor = new Processor();
        $configuration = new Validator();
        try {
            $processedConfig = $processor->processConfiguration($configuration, array($config));
        } catch (InvalidConfigurationException $e) {
            throw new \DomainException($e->getMessage());
        }
        return $processedConfig;
    }

Usage Example

Example #1
0
 public function testLoad()
 {
     $helper = new Helper();
     $cfg = $helper->getConfig(dirname(__DIR__) . '/Fixtures');
     $this->assertArrayHasKey('SomeClass::someMethod', $cfg['graph']['calling']);
 }