2 /** @package verysimple::Phreeze */
3 require_once ("IRenderEngine.php");
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
15 class PHPRenderEngine
implements IRenderEngine
{
17 * the file path to the template director
22 * if this is true, all views will have .
23 * php appended the last 4 chars are not .php
25 public $verifyExtension = true;
28 * stores the assigned vars
30 public $model = Array ();
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
.= "/";
48 public function assign($key, $value) {
49 $this->model
[$key] = $value;
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'] );
60 } elseif ($template == "_error.tpl") {
61 die ( "<h4>" . $this->model
['message'] . "</h4>" . $this->model
['stacktrace'] );
63 if ($this->verifyExtension
&& substr ( $template, - 4 ) != '.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
74 $model = $this->model
;
80 * Returns the specified model value
82 public function get($key) {
83 return $this->model
[$key];
89 public function fetch($template) {
92 $this->display ( $template );
93 $buffer = ob_get_contents ();
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()