/** * {@inheritDoc} */ public function register(Application $app) { $app['config.paths'] = function (Application $app) { return array($app['root_dir'] . '/config', $app['root_dir']); }; $app['config.locator'] = $app->share(function (Application $app) { return new FileLocator($app['config.paths']); }); $app['config.resource_collection'] = $app->share(function (Application $app) { return new ResourceCollection(); }); $app['config.normalizer'] = $app->share(function (Application $app) { $normalizer = new ChainNormalizer(); $normalizer->add(new PimpleNormalizer($app)); $normalizer->add(new EnvironmentNormalizer()); return $normalizer; }); $app['config.loader'] = $app->share(function (Application $app) { $loader = new NormalizerLoader(new DelegatingLoader($app['config.loader_resolver']), $app['config.normalizer']); $loader = new CacheLoader($loader, $app['config.resource_collection']); $loader->setCacheDir($app['config.cache_dir']); $loader->setDebug($app['debug']); return $loader; }); $app['config.loader_resolver'] = $app->share(function ($app) { return new LoaderResolver(array(new JsonFileLoader($app['config.locator'], $app['config.resource_collection']), new IniFileLoader($app['config.locator'], $app['config.resource_collection']), new PhpFileLoader($app['config.locator'], $app['config.resource_collection']), new YamlFileLoader($app['config.locator'], $app['config.resource_collection']))); }); $app['configurator'] = $app->share(function (Application $app) { return new Configurator($app['config.loader']); }); if (!isset($app['config.cache_dir'])) { $app['config.cache_dir'] = null; } }
public function register(Application $app) { $cacheKey = sprintf('%s.cache_dir', $this->prefix); $loaderKey = sprintf('%s.loader', $this->prefix); $locatorKey = sprintf('%s.locator', $this->prefix); $pathsKey = sprintf('%s.paths', $this->prefix); $resolverKey = sprintf('%s.resolver', $this->prefix); $resourcesKey = sprintf('%s.resources', $this->prefix); if (!isset($app[$pathsKey])) { $app[$pathsKey] = []; } if (!isset($app[$cacheKey])) { $app[$cacheKey] = null; } $app[$locatorKey] = $app->share(function (Application $app) use($pathsKey) { return new FileLocator($app[$pathsKey]); }); $app[$resourcesKey] = $app->share(function () { return new ResourceCollection(); }); $app[$resolverKey] = $app->share(function (Application $app) use($locatorKey, $resourcesKey) { return new LoaderResolver([new JsonFileLoader($app[$locatorKey], $app[$resourcesKey]), new IniFileLoader($app[$locatorKey], $app[$resourcesKey]), new PhpFileLoader($app[$locatorKey], $app[$resourcesKey]), new YamlFileLoader($app[$locatorKey], $app[$resourcesKey])]); }); $app[$loaderKey] = $app->share(function (Application $app) use($cacheKey, $resolverKey, $resourcesKey) { $normalizer = new ChainNormalizer(); $normalizer->add(new PimpleNormalizer($app)); $normalizer->add(new EnvironmentNormalizer()); $loader = new CacheLoader(new NormalizerLoader(new DelegatingLoader($app[$resolverKey]), $normalizer), $app[$resourcesKey]); $loader->setDebug($app['debug']); $loader->setCacheDir($app[$cacheKey]); return $loader; }); $app[$this->prefix] = $app->share(function (Application $app) use($loaderKey) { $configurator = new Configurator($app[$loaderKey]); return $configurator; }); }