1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This is part of the webuni/front-matter package. |
5
|
|
|
* |
6
|
|
|
* (c) Martin Hasoň <[email protected]> |
7
|
|
|
* (c) Webuni s.r.o. <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Webuni\FrontMatter\Twig; |
14
|
|
|
|
15
|
|
|
use Webuni\FrontMatter\FrontMatterInterface; |
16
|
|
|
|
17
|
|
|
class FrontMatterLoader implements \Twig_LoaderInterface, \Twig_ExistsLoaderInterface, \Twig_SourceContextLoaderInterface |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
private $loader; |
20
|
|
|
private $parser; |
21
|
|
|
|
22
|
|
|
public function __construct(FrontMatterInterface $parser, \Twig_LoaderInterface $loader) |
23
|
|
|
{ |
24
|
|
|
$this->loader = $loader; |
25
|
|
|
$this->parser = $parser; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getSource($name) |
29
|
|
|
{ |
30
|
|
|
@trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since Twig 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); |
|
|
|
|
31
|
|
|
|
32
|
|
|
return $this->getSourceContext($name); |
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getCacheKey($name) |
36
|
|
|
{ |
37
|
|
|
return $this->loader->getCacheKey($name); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function isFresh($name, $time) |
41
|
|
|
{ |
42
|
|
|
return $this->loader->isFresh($name, $time); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function exists($name) |
46
|
|
|
{ |
47
|
|
|
if ($this->loader instanceof \Twig_ExistsLoaderInterface) { |
48
|
|
|
return $this->loader->exists($name); |
49
|
|
|
} else { |
50
|
|
|
try { |
51
|
|
|
if ($this->loader instanceof \Twig_SourceContextLoaderInterface) { |
52
|
|
|
$this->loader->getSourceContext($name); |
53
|
|
|
} else { |
54
|
|
|
$this->loader->getSource($name); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return true; |
58
|
|
|
} catch (\Twig_Error_Loader $e) { |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getSourceContext($name) |
65
|
|
|
{ |
66
|
|
|
if ($this->loader instanceof \Twig_SourceContextLoaderInterface) { |
67
|
|
|
$source = $this->loader->getSourceContext($name); |
68
|
|
|
} else { |
69
|
|
|
if ($this->loader instanceof \Twig_ExistsLoaderInterface && !$this->loader->exists($name)) { |
70
|
|
|
throw new \Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$source = new \Twig_Source($this->loader->getSource($name), $name); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return new \Twig_Source($this->parser->parse($source->getCode(), ['filename' => $name]), $source->getName(), $source->getPath()); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.