Completed
Pull Request — 1.4 (#77)
by
unknown
02:19
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
     * @param string $name
24
     */
25
    public function getCacheKey($name): string
26
    {
27
        return $name;
28
    }
29
    /**
30
     * {@inheritdoc}
31
     *
32
     * @param string $name
33
     * @param int $time
34
     */
35
    public function isFresh($name, $time): bool
36
    {
37
        return true;
38
    }
39
40
    /**
41
     * Returns the source context for a given template logical name.
42
     *
43
     * @param string $name The template logical name
44
     *
45
     * @return Source
46
     */
47
    public function getSourceContext($name): Source
48
    {
49
        return new Source($name, $name);
50
    }
51
52
    /**
53
     * Check if we have the source code of a template, given its name.
54
     *
55
     * @param string $name The name of the template to check if we can load
56
     *
57
     * @return bool If the template source code is handled by this loader or not
58
     */
59
    public function exists($name)
60
    {
61
        return true;
62
    }
63
}
64