X-Git-Url: https://projects.mako.cc/source/scuttle/blobdiff_plain/c20b44263a89d8bf1a78bfa632daaae3cb4f1da2..HEAD:/services/templateservice.php?ds=sidebyside diff --git a/services/templateservice.php b/services/templateservice.php index 191ab8d..6675462 100644 --- a/services/templateservice.php +++ b/services/templateservice.php @@ -1,46 +1,48 @@ basedir = $GLOBALS['TEMPLATES_DIR']; + var $basedir; + + function &getInstance() { + static $instance; + if (!isset($instance)) { + $instance = new TemplateService(); } - - function loadTemplate($template, $vars = NULL) { - if (substr($template, -4) != '.php') - $template .= '.php'; - $tpl =& new Template($this->basedir .'/'. $template, $vars, $this); - $tpl->parse(); - return $tpl; + return $instance; + } + + function __construct() { + $this->basedir = $GLOBALS['TEMPLATES_DIR']; + } + + function loadTemplate($template, $vars = NULL) { + if (substr($template, -4) != '.php') { + $template .= '.php'; } + $tpl = new Template($this->basedir .'/'. $template, $vars, $this); + $tpl->parse(); + return $tpl; + } } class Template { - var $vars = array(); - var $file = ''; - var $templateservice; - - function Template($file, $vars = NULL, &$templateservice) { - $this->vars = $vars; - $this->file = $file; - $this->templateservice = $templateservice; - } - - function parse() { - if (isset($this->vars)) - extract($this->vars); - include($this->file); - } - - function includeTemplate($name) { - return $this->templateservice->loadTemplate($name, $this->vars); + var $vars = array(); + var $file = ''; + var $templateservice; + + function __construct($file, $vars = NULL, &$templateservice) { + $this->vars = $vars; + $this->file = $file; + $this->templateservice = $templateservice; + } + + function parse() { + if (isset($this->vars)) { + extract($this->vars); } + include $this->file; + } + + function includeTemplate($name) { + return $this->templateservice->loadTemplate($name, $this->vars); + } } -?> \ No newline at end of file