1 | <?php |
||
9 | class TemplateCacheCacheWarmer implements CacheWarmerInterface |
||
10 | { |
||
11 | protected $container; |
||
12 | protected $finder; |
||
13 | |||
14 | /** |
||
15 | * Constructor. |
||
16 | * |
||
17 | * @param ContainerInterface $container The dependency injection container |
||
18 | * @param TemplateFinderInterface $finder The template paths cache warmer |
||
19 | */ |
||
20 | public function __construct(ContainerInterface $container, TemplateFinderInterface $finder) |
||
29 | |||
30 | /** |
||
31 | * Warms up the cache. |
||
32 | * |
||
33 | * @param string $cacheDir The cache directory |
||
34 | */ |
||
35 | public function warmUp($cacheDir) |
||
36 | { |
||
37 | $twig = $this->container->get('twig'); |
||
38 | |||
39 | foreach ($this->finder->findAllTemplates() as $template) { |
||
40 | |||
41 | if ('twital' !== $template->get('engine')) { |
||
42 | continue; |
||
43 | } |
||
44 | |||
45 | try { |
||
46 | $twig->loadTemplate($template); |
||
47 | } catch (\Twig_Error $e) { |
||
48 | // problem during compilation, give up |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Checks whether this warmer is optional or not. |
||
55 | * |
||
56 | * @return bool always true |
||
57 | */ |
||
58 | public function isOptional() |
||
62 | } |
||
63 |