Completed
Branch 09branch (31301e)
by Anton
02:42
created

LoaderBridge::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * spiral
4
 *
5
 * @author    Wolfy-J
6
 */
7
8
namespace Spiral\Views\Engines\Twig;
9
10
use Spiral\Views\LoaderInterface;
11
12
/**
13
 * Bridge between twig loader and spiral loader (i wish twig use interface for context).
14
 */
15
class LoaderBridge implements \Twig_LoaderInterface
16
{
17
    /**
18
     * @var \Spiral\Views\LoaderInterface
19
     */
20
    private $loader;
21
22
    /**
23
     * @param \Spiral\Views\LoaderInterface $loader
24
     */
25
    public function __construct(LoaderInterface $loader)
26
    {
27
        $this->loader = $loader;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getSourceContext($name)
34
    {
35
        $context = $this->loader->getSource($name);
36
37
        return new \Twig_Source(
38
            $context->getCode(),
39
            $context->getName(),
40
            $context->getFilename()
41
        );
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getCacheKey($name)
48
    {
49
        return $this->loader->getSource($name)->getFilename();
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function isFresh($name, $time)
56
    {
57
        return !$this->loader->getSource($name)->isFresh($time);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function exists($name)
64
    {
65
        return $this->loader->exists($name);
66
    }
67
}