tarsana /
command
| 1 | <?php namespace Tarsana\Command\Template\Twig; |
||||
| 2 | |||||
| 3 | use Tarsana\Command\Interfaces\Template\TemplateInterface; |
||||
| 4 | use Tarsana\Command\Interfaces\Template\TemplateLoaderInterface; |
||||
| 5 | use Tarsana\Command\Template\Twig\TwigTemplate; |
||||
| 6 | |||||
| 7 | /** |
||||
| 8 | * Twig Templates Loader |
||||
| 9 | */ |
||||
| 10 | class TwigLoader implements TemplateLoaderInterface { |
||||
| 11 | |||||
| 12 | /** |
||||
| 13 | * Twig Environment. |
||||
| 14 | * |
||||
| 15 | * @var \Twig_Environment |
||||
| 16 | */ |
||||
| 17 | protected $env; |
||||
| 18 | |||||
| 19 | /** |
||||
| 20 | * Initialize the loader. |
||||
| 21 | * |
||||
| 22 | * @param string $templatesPath |
||||
| 23 | * @param string $cachePath |
||||
| 24 | * @return self |
||||
| 25 | */ |
||||
| 26 | public function init(string $templatesPath, string $cachePath = null) : TemplateLoaderInterface |
||||
| 27 | { |
||||
| 28 | $loader = new \Twig_Loader_Filesystem($templatesPath); |
||||
|
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||||
| 29 | if (null !== $cachePath) { |
||||
| 30 | $this->env = new \Twig_Environment($loader, [ |
||||
|
0 ignored issues
–
show
The class
Twig_Environment has been deprecated: since Twig 2.7, use "Twig\Environment" instead
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 31 | 'cache' => $cachePath, |
||||
| 32 | ]); |
||||
| 33 | } else { |
||||
| 34 | $this->env = new \Twig_Environment($loader); |
||||
|
0 ignored issues
–
show
The class
Twig_Environment has been deprecated: since Twig 2.7, use "Twig\Environment" instead
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 35 | } |
||||
| 36 | return $this; |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | /** |
||||
| 40 | * Loads a template. |
||||
| 41 | * |
||||
| 42 | * @param string $name |
||||
| 43 | * @return Tarsana\Command\Template\Twig\TwigTemplate |
||||
|
0 ignored issues
–
show
|
|||||
| 44 | */ |
||||
| 45 | public function load(string $name) : TemplateInterface |
||||
| 46 | { |
||||
| 47 | return new TwigTemplate($this->env->loadTemplate($name)); |
||||
|
0 ignored issues
–
show
|
|||||
| 48 | } |
||||
| 49 | |||||
| 50 | } |
||||
| 51 |