1 | <?php |
||
28 | class TwigTemplateCacheWarmer implements CacheWarmerInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var ResourceRepository |
||
32 | */ |
||
33 | private $repo; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $suffix; |
||
39 | |||
40 | /** |
||
41 | * @var Twig_Environment |
||
42 | */ |
||
43 | private $twig; |
||
44 | |||
45 | 1 | public function __construct(ResourceRepository $repo, Twig_Environment $twig, $suffix = '.twig') |
|
51 | |||
52 | /** |
||
53 | * Warms up the cache. |
||
54 | * |
||
55 | * @param string $cacheDir The cache directory |
||
56 | * |
||
57 | * @throws RuntimeException If setEnvironment() wasn't called |
||
58 | */ |
||
59 | 1 | public function warmUp($cacheDir) |
|
60 | { |
||
61 | 1 | $iterator = new ResourceFilterIterator( |
|
62 | 1 | new RecursiveResourceIteratorIterator( |
|
63 | 1 | new ResourceCollectionIterator( |
|
64 | 1 | $this->repo->get('/')->listChildren(), |
|
65 | 1 | ResourceCollectionIterator::CURRENT_AS_PATH |
|
66 | ), |
||
67 | 1 | RecursiveResourceIteratorIterator::SELF_FIRST |
|
68 | ), |
||
69 | 1 | $this->suffix, |
|
70 | 1 | ResourceFilterIterator::FILTER_BY_NAME | ResourceFilterIterator::MATCH_SUFFIX |
|
71 | ); |
||
72 | |||
73 | 1 | foreach ($iterator as $path) { |
|
74 | try { |
||
75 | 1 | $this->twig->loadTemplate($path); |
|
76 | 1 | } catch (Twig_Error $e) { |
|
77 | // Problem during compilation, stop |
||
78 | } |
||
79 | } |
||
80 | 1 | } |
|
81 | |||
82 | /** |
||
83 | * Returns whether this warmer is optional or not. |
||
84 | * |
||
85 | * @return bool always true |
||
86 | */ |
||
87 | public function isOptional() |
||
91 | } |
||
92 |