1 | <?php |
||
14 | class YamlRouteServiceProvider implements ServiceProviderInterface |
||
15 | { |
||
16 | protected $cacheDirPath; |
||
17 | protected $configFilePath; |
||
18 | protected $configCacheFactory; |
||
19 | |||
20 | /** |
||
21 | * @param string $configFilePath Path to config file |
||
22 | * @param null|array $options Provider options |
||
23 | */ |
||
24 | public function __construct($configFilePath, $options = null) |
||
34 | |||
35 | public function register(Application $app) |
||
36 | { |
||
37 | $app['routes'] = $app->share($app->extend('routes', function(RouteCollection $routes, Application $app) { |
||
38 | if ($this->cacheDirPath) { |
||
39 | $cache = $this->getConfigCacheFactory($app['debug'])->cache($this->cacheDirPath.'/routes.cache.php', |
||
40 | function(ConfigCacheInterface $cache) { |
||
41 | $collection = $this->loadRouteCollection(); |
||
42 | |||
43 | $content = PhpRouteCollectionDumper::dump($collection); |
||
44 | |||
45 | $cache->write($content, $collection->getResources()); |
||
46 | } |
||
47 | ); |
||
48 | |||
49 | $collection = include $cache->getPath(); |
||
50 | } else { |
||
51 | $collection = $this->loadRouteCollection(); |
||
52 | } |
||
53 | |||
54 | $routes->addCollection($collection); |
||
55 | |||
56 | return $routes; |
||
57 | })); |
||
58 | } |
||
59 | |||
60 | public function boot(Application $app) |
||
63 | |||
64 | /** |
||
65 | * @param bool $debug Is debug mode enabled |
||
66 | * |
||
67 | * @return ConfigCacheFactory |
||
68 | */ |
||
69 | private function getConfigCacheFactory($debug) |
||
77 | |||
78 | protected function loadRouteCollection() |
||
86 | } |
||
87 |