/** * Creates a Wisdom service provider. * * @param Application $app The Silex application. * @param string $serviceName The new service name. * @param string $pathName The new path parameter name. * @param string $optionsName The new options parameter name. */ public static function createService(Application $app, $serviceName, $pathName, $optionsName) { $app[$optionsName] = array(); $app[$serviceName] = $app->share(function () use($app, $serviceName, $pathName, $optionsName) { $app[$optionsName] = array_merge(array('cache_path' => '', 'debug' => $app['debug'], 'prefix' => $app['debug'] ? 'dev.' : 'prod.'), $app[$optionsName]); if (false === isset($app[$optionsName]['loaders'])) { $options = $app[$optionsName]; $options['loaders'] = array('KevinGH\\Wisdom\\Loader\\INI', 'KevinGH\\Wisdom\\Loader\\JSON'); if (class_exists('Symfony\\Component\\Yaml\\Yaml')) { $options['loaders'][] = 'KevinGH\\Wisdom\\Loader\\YAML'; } $app[$optionsName] = $options; } $wisdom = new Wisdom($app[$pathName]); $wisdom->setCache($app[$optionsName]['cache_path']); $wisdom->setDebug($app[$optionsName]['debug']); $wisdom->setPrefix($app[$optionsName]['prefix']); $wisdom->setValues($app); foreach ((array) $app[$optionsName]['loaders'] as $class) { $wisdom->addLoader(new $class()); } return $wisdom; }); }
/** * @expectedException InvalidArgumentException * @expectedExceptionMessage No loader available for file: test.yml */ public function testGetMissingLoader() { unlink($dir = tempnam(sys_get_temp_dir(), 'wis')); mkdir($dir); file_put_contents($dir . '/test.yml', <<<YAML rand: %rand% YAML ); $wisdom = new Wisdom($dir); $wisdom->get('test.yml'); }