New onsite patient portal, take 4.
[openemr.git] / portal / patient / fwk / libs / verysimple / Phreeze / PHPRenderEngine.php
blob215ec0fbb1c33a66abafbb3faa2a72fd4b6c647f
1 <?php
2 /** @package verysimple::Phreeze */
3 require_once ("IRenderEngine.php");
5 /**
6 * PHPRenderEngine is an implementation of IRenderEngine
7 * that uses PHP 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 PHPRenderEngine implements IRenderEngine {
16 /**
17 * the file path to the template director
19 public $tempatePath;
21 /**
22 * if this is true, all views will have .
23 * php appended the last 4 chars are not .php
25 public $verifyExtension = true;
27 /**
28 * stores the assigned vars
30 public $model = Array ();
32 /**
34 * @param string $templatePath
35 * @param string $compilePath
36 * (not used for this render engine)
38 function __construct($templatePath = '', $compilePath = '') {
39 $this->templatePath = $templatePath;
41 if (substr ( $this->templatePath, - 1 ) != '/' && substr ( $this->templatePath, - 1 ) != '\\')
42 $this->templatePath .= "/";
45 /**
46 * @inheritdoc
48 public function assign($key, $value) {
49 $this->model [$key] = $value;
52 /**
53 * @inheritdoc
55 public function display($template) {
56 // these two are special templates used by the Phreeze controller and dispatcher
57 if ($template == "_redirect.tpl") {
58 header ( "Location: " . $this->model ['url'] );
59 die ();
60 } elseif ($template == "_error.tpl") {
61 die ( "<h4>" . $this->model ['message'] . "</h4>" . $this->model ['stacktrace'] );
62 } else {
63 if ($this->verifyExtension && substr ( $template, - 4 ) != '.php')
64 $template .= ".php";
66 $path = $this->templatePath . $template;
68 if (! is_readable ( $path )) {
69 throw new Exception ( "The template file '" . htmlspecialchars ( $path ) . "' was not found." );
72 // make this available at the scope of the included file
73 $engine = $this;
74 $model = $this->model;
75 include_once ($path);
79 /**
80 * Returns the specified model value
82 public function get($key) {
83 return $this->model [$key];
86 /**
87 * @inheritdoc
89 public function fetch($template) {
90 ob_start ();
92 $this->display ( $template );
93 $buffer = ob_get_contents ();
95 ob_end_clean ();
97 return $buffer;
102 * @see IRenderEngine::clear()
104 function clear($key) {
105 if (array_key_exists ( $key, $this->model ))
106 unset ( $this->model [$key] );
111 * @see IRenderEngine::clearAll()
113 function clearAll() {
114 $this->model == array ();
119 * @see IRenderEngine::getAll()
121 function getAll() {
122 return $this->model;