Highway to PSR2
[openemr.git] / portal / patient / fwk / libs / verysimple / Phreeze / SavantRenderEngine.php
blobe2cb5298c23dec8e37fc040ee1bc2e695125cb93
1 <?php
2 /** @package verysimple::Phreeze */
3 require_once("IRenderEngine.php");
4 require_once('savant/Savant3.php');
6 /**
7 * Implementation of IRenderEngine that uses Savant as the template language
9 * @package verysimple::Phreeze
10 * @author VerySimple Inc.
11 * @copyright 1997-2010 VerySimple, Inc.
12 * @license http://www.gnu.org/licenses/lgpl.html LGPL
13 * @version 1.0
15 class SavantRenderEngine implements IRenderEngine
17 static $TEMPLATE_EXTENSION = ".tpl.php";
19 /** @var Savant3 */
20 public $savant;
22 /**
24 * @param string $templatePath
25 * @param string $compilePath
26 * (not used for this render engine)
28 function __construct($templatePath = '', $compilePath = '')
30 $this->savant = new Savant3(array (
31 'exceptions' => true
32 ));
34 // normalize the path
35 if (substr($templatePath, - 1) != '/' && substr($templatePath, - 1) != '\\') {
36 $templatePath .= "/";
39 if ($templatePath) {
40 $this->savant->setPath('template', $templatePath);
44 /**
45 * @inheritdoc
47 public function assign($key, $value)
49 $this->savant->$key = $value;
52 /**
53 * @inheritdoc
55 public function display($template)
57 // strip off .tpl from the end for backwards compatibility with older apps
58 if (substr($template, - 4) == '.tpl') {
59 $template = substr($template, 0, - 4);
62 // these two are special templates used by the Phreeze controller and dispatcher
63 if ($template == "_redirect") {
64 header("Location: " . $this->savant->url);
65 die();
66 } elseif ($template == "_error") {
67 $this->savant->display('_error' . self::$TEMPLATE_EXTENSION);
68 } else {
69 $this->savant->display($template . self::$TEMPLATE_EXTENSION);
73 /**
74 * Returns the specified model value
76 public function get($key)
78 return $this->savant->$key;
81 /**
82 * @inheritdoc
84 public function fetch($template)
86 return $this->savant->fetch($template . self::$TEMPLATE_EXTENSION);
89 /**
91 * @see IRenderEngine::clear()
93 function clear($key)
95 if (array_key_exists($key, $this->savant)) {
96 unset($this->savant [$key]);
102 * @see IRenderEngine::clearAll()
104 function clearAll()
106 throw new Exception('clearAll not implemented for SavantRenderEngine');
111 * @see IRenderEngine::getAll()
113 function getAll()
115 return get_object_vars($this->savant);