Highway to PSR2
[openemr.git] / portal / patient / fwk / libs / verysimple / Phreeze / TwigRenderEngine.php
blob867e85cb543ca27ac75cca15c95204a863e30592
1 <?php
2 /** @package verysimple::Phreeze */
4 /**
5 * import supporting libraries
6 */
7 require_once("verysimple/Phreeze/IRenderEngine.php");
8 require_once 'Twig/Autoloader.php';
9 Twig_Autoloader::register();
11 /**
12 * TwigRenderEngine is an implementation of IRenderEngine that uses
13 * the Twig template engine to render views
15 * @package verysimple::Phreeze
16 * @author VerySimple Inc.
17 * @copyright 1997-2011 VerySimple, Inc.
18 * @license http://www.gnu.org/licenses/lgpl.html LGPL
19 * @version 1.0
21 class TwigRenderEngine implements IRenderEngine
24 /** @var Twig_Environment */
25 public $twig;
27 /** @var Twig_Loader_Filesystem */
28 private $loader;
29 private $assignments = array ();
31 /**
33 * @param string $templatePath
34 * @param string $compilePath
36 function __construct($templatePath = '', $compilePath = '')
38 $this->loader = new Twig_Loader_Filesystem($templatePath);
39 $this->twig = new Twig_Environment($this->loader, array (
40 'cache' => $compilePath
41 ));
44 /**
46 * @see IRenderEngine::assign()
48 function assign($key, $value)
50 return $this->assignments [$key] = $value;
53 /**
55 * @see IRenderEngine::display()
57 function display($template)
59 if (strpos('.', $template) === false) {
60 $template .= '.html';
63 return $this->twig->display($template, $this->assignments);
66 /**
68 * @see IRenderEngine::fetch()
70 function fetch($template)
72 if (strpos('.', $template) === false) {
73 $template .= '.html';
76 return $this->twig->render($template, $this->assignments);
79 /**
81 * @see IRenderEngine::clear()
83 function clear($key)
85 unset($this->assignments [$key]);
88 /**
90 * @see IRenderEngine::clearAll()
92 function clearAll()
94 $this->assignments = array ();
97 /**
99 * @see IRenderEngine::getAll()
101 function getAll()
103 return $this->assignments;