5 private $data = array();
7 public static function render($name, Array $data)
9 $template = new Template($name);
10 $template->addData($data);
11 return $template->fillIn();
14 public function __construct($name)
16 if (strpos($name, '../') !== false)
17 throw new Exception("Template name contains illegal path component.");
19 $this->path = $this->getPath($name);
21 if ($this->path === false)
22 throw new Exception("Template $name not found in templates/ directory.");
24 if (!is_readable($this->path))
25 throw new Exception("Template $name not readable.");
28 protected function getPath($name)
30 $path = Application::get()->getBaseDir() . 'templates/' . $name . '.phtml';
31 if (file_exists($path)) return $path;
36 public function add($name, $value)
38 $this->data[$name] = $value;
41 public function addData(Array $data)
43 foreach ($data as $name => $value)
44 $this->data[$name] = $value;
47 public function fillIn()
53 $text = ob_get_clean();