Completed
Push — master ( b95763...2cb7d7 )
by Nikola
29:49
created

QuerySourcesCacheWarmer::isOptional()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace RunOpenCode\Bundle\QueryResourcesLoader\Twig\CacheWarmer;
4
5
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
6
7
class QuerySourcesCacheWarmer implements CacheWarmerInterface
8
{
9
    private $twig;
10
    private $iterator;
11
12
    public function __construct(\Twig_Environment $twig, \Traversable $iterator)
13
    {
14
        $this->twig = $twig;
15
        $this->iterator = $iterator;
16
    }
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function warmUp($cacheDir)
22
    {
23
        foreach ($this->iterator as $template) {
24
            try {
25
                $this->twig->loadTemplate($template);
26
            } catch (\Twig_Error $e) {
27
                // problem during compilation, give up
28
                // might be a syntax error or a non-Twig template
29
            }
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function isOptional()
37
    {
38
        return true;
39
    }
40
}
41