Completed
Pull Request — 1.2 (#39)
by David
47:12 queued 40:35
created

StringLoader::getSourceContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Mouf\Database\MagicQuery\Twig;
4
use Twig_Error_Loader;
5
use Twig_Source;
6
7
/**
8
 * This loader completely bypasses the loader mechanism, by directly passing the key as a template.
9
 * Useful in our very case.
10
 *
11
 * This is a reimplementation of Twig's String loader that has been deprecated.
12
 * We enable it back in our case because there won't be a million of different cache keys.
13
 * And yes, we know what we are doing :)
14
 */
15
class StringLoader implements \Twig_LoaderInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function getSource($name)
21
    {
22
        return $name;
23
    }
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getCacheKey($name)
28
    {
29
        return $name;
30
    }
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function isFresh($name, $time)
35
    {
36
        return true;
37
    }
38
39
    /**
40
     * Returns the source context for a given template logical name.
41
     *
42
     * @param string $name The template logical name
43
     *
44
     * @return Twig_Source
45
     *
46
     * @throws Twig_Error_Loader When $name is not found
47
     */
48
    public function getSourceContext($name)
49
    {
50
        return new Twig_Source($name, $name);
51
    }
52
53
    /**
54
     * Check if we have the source code of a template, given its name.
55
     *
56
     * @param string $name The name of the template to check if we can load
57
     *
58
     * @return bool If the template source code is handled by this loader or not
59
     */
60
    public function exists($name)
61
    {
62
        return true;
63
    }
64
}
65