Passed
Push — master ( f28aa5...f8cd9d )
by Mike
08:28
created

XerviceLoader::findTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Twig\Business\Loader;
6
7
8
use Xervice\Twig\Business\Path\PathCollection;
9
10
class XerviceLoader implements \Twig_LoaderInterface, XerviceLoaderInterface
11
{
12
    protected const XERVICE_NAMESPACE = '__main__';
13
14
    /**
15
     * @var \Twig_Loader_Filesystem
16
     */
17
    private $twigFilesystemLoader;
18
19
    /**
20
     * @var \Xervice\Twig\Business\Path\PathCollection
21
     */
22
    private $pathProviderCollection;
23
24
    /**
25
     * XerviceLoader constructor.
26
     *
27
     * @param \Twig_Loader_Filesystem $twigFilesystemLoader
28
     * @param \Xervice\Twig\Business\Path\PathCollection $pathProviderCollection
29
     */
30 2
    public function __construct(
31
        \Twig_Loader_Filesystem $twigFilesystemLoader,
32
        PathCollection $pathProviderCollection
33
    ) {
34 2
        $this->twigFilesystemLoader = $twigFilesystemLoader;
35 2
        $this->pathProviderCollection = $pathProviderCollection;
36
37 2
        $this->providePaths();
38 2
    }
39
40
    /**
41
     * @param string $path
42
     * @param string $namespace
43
     *
44
     * @throws \Twig_Error_Loader
45
     */
46 2
    public function addPath(string $path, string $namespace = self::XERVICE_NAMESPACE): void
47
    {
48 2
        $this->twigFilesystemLoader->addPath($path, $namespace);
49 2
    }
50
51
    /**
52
     * @param string $name
53
     *
54
     * @return \Twig_Source
55
     * @throws \Twig_Error_Loader
56
     */
57 2
    public function getSourceContext($name): \Twig_Source
58
    {
59 2
        return $this->twigFilesystemLoader->getSourceContext($name);
60
    }
61
62
    /**
63
     * @param string $name
64
     *
65
     * @return string
66
     * @throws \Twig_Error_Loader
67
     */
68 2
    public function getCacheKey($name): string
69
    {
70 2
        return $this->twigFilesystemLoader->getCacheKey($name);
71
    }
72
73
    /**
74
     * @param string $name
75
     * @param int $time
76
     *
77
     * @return bool
78
     * @throws \Twig_Error_Loader
79
     */
80
    public function isFresh($name, $time): bool
81
    {
82
        return $this->twigFilesystemLoader->isFresh($name, $time);
83
    }
84
85
    /**
86
     * @param string $name
87
     *
88
     * @return bool
89
     */
90
    public function exists($name): bool
91
    {
92
        return $this->twigFilesystemLoader->exists($name);
93
    }
94
95 2
    protected function providePaths(): void
96
    {
97 2
        foreach ($this->pathProviderCollection as $pathProvider) {
98
            $pathProvider->privideTwigPaths($this);
99
        }
100
    }
101
}