phpmyadmin/libraries/Template.class.php
Jason ce3c8b0c66 Refactoring tbl_view.lib and add PMA\Template
Signed-off-by: Jason <jason.daurus@gmail.com>
2015-05-15 03:48:25 +08:00

44 lines
948 B
PHP

<?php
namespace PMA;
if (! defined('PHPMYADMIN')) {
exit;
}
class Template {
protected $name = null;
const BASE_PATH = 'templates/';
protected function __construct($name)
{
$this->name = $name;
}
public static function get($name)
{
return new Template($name);
}
public function render($data = array())
{
$template = static::BASE_PATH . $this->name . '.php';
try {
extract($data);
ob_start();
if (file_exists($template)) {
include $template;
} else {
throw new \LogicException(
'The template "' . $template . '" not found.'
);
}
$content = ob_get_clean();
return $content;
} catch (\LogicException $e) {
ob_end_clean();
throw new \LogicException($e->getMessage());
}
}
}