Completed
Pull Request — 1.4 (#79)
by
unknown
13:18
created

StringLoader::getSource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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