1 | <?php |
||
12 | class YamlConfigurationServiceProvider implements ServiceProviderInterface |
||
13 | { |
||
14 | protected $cacheDirPath; |
||
15 | protected $configFilePath; |
||
16 | protected $configCacheFactory; |
||
17 | |||
18 | public function __construct($configFilePath, $options = null) |
||
28 | |||
29 | public function register(Application $app) |
||
30 | { |
||
31 | $app['config'] = $app->share(function(Application $app) { |
||
32 | if ($this->cacheDirPath) { |
||
33 | $cache = $this->getConfigCacheFactory($app['debug'])->cache($this->cacheDirPath.'/config.cache.php', |
||
34 | function(ConfigCacheInterface $cache) { |
||
35 | $config = $this->loadConfig(); |
||
36 | |||
37 | $content = sprintf('<?php use Junker\Silex\Config; $c = new Config(%s);', var_export($config->data, true)).PHP_EOL; |
||
38 | $content .= 'return $c;'; |
||
39 | |||
40 | $cache->write($content, $config->getResources()); |
||
41 | } |
||
42 | ); |
||
43 | |||
44 | $config = include $cache->getPath(); |
||
45 | } else { |
||
46 | $config = $this->loadConfig(); |
||
47 | } |
||
48 | |||
49 | return $config->data; |
||
50 | }); |
||
51 | } |
||
52 | |||
53 | public function boot(Application $app) |
||
56 | |||
57 | private function getConfigCacheFactory($debug = false) |
||
65 | |||
66 | protected function loadConfig() |
||
74 | } |
||
75 |