diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-08 12:48:08 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2018-09-09 12:11:12 +0200 |
commit | 222c9fed7d4ca2b3b44c05907fbb7080c1efd342 (patch) | |
tree | 62b1bfa9233000985331b9dea703d51dc24515a2 /src/Renderer/TwigEngine.php | |
parent | 2d6bca1357faff28bc1f86a56b432cc463ff7574 (diff) | |
parent | 8257864829ffdfb410f05e0dd0a9c781f48b741a (diff) |
Merge remote-tracking branch 'MyIgel/templating'
Diffstat (limited to 'src/Renderer/TwigEngine.php')
-rw-r--r-- | src/Renderer/TwigEngine.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Renderer/TwigEngine.php b/src/Renderer/TwigEngine.php new file mode 100644 index 00000000..55a2e299 --- /dev/null +++ b/src/Renderer/TwigEngine.php @@ -0,0 +1,41 @@ +<?php + +namespace Engelsystem\Renderer; + +use Twig_Environment as Twig; +use Twig_Error_Loader as LoaderError; +use Twig_Error_Runtime as RuntimeError; +use Twig_Error_Syntax as SyntaxError; + +class TwigEngine implements EngineInterface +{ + /** @var Twig */ + protected $twig; + + public function __construct(Twig $twig) + { + $this->twig = $twig; + } + + /** + * Render a twig template + * + * @param string $path + * @param array $data + * @return string + * @throws LoaderError|RuntimeError|SyntaxError + */ + public function get($path, $data = []) + { + return $this->twig->render($path, $data); + } + + /** + * @param string $path + * @return bool + */ + public function canRender($path) + { + return $this->twig->getLoader()->exists($path); + } +} |