addData($data); return $template->fillIn(); } public function __construct($name) { if (strpos($name, '../') !== false) throw new Exception("Template name contains illegal path component."); $this->path = $this->getPath($name); if ($this->path === false) throw new Exception("Template $name not found in templates/ directory."); if (!is_readable($this->path)) throw new Exception("Template $name not readable."); } protected function getPath($name) { $path = Application::get()->getBaseDir() . 'templates/' . $name . '.phtml'; if (file_exists($path)) return $path; return false; } public function add($name, $value) { $this->data[$name] = $value; } public function addData(Array $data) { foreach ($data as $name => $value) $this->data[$name] = $value; } public function fillIn() { extract($this->data); ob_start(); include($this->path); $text = ob_get_clean(); return $text; } }