X-Git-Url: https://projects.mako.cc/source/scuttle/blobdiff_plain/c20b44263a89d8bf1a78bfa632daaae3cb4f1da2..a4d4c86c4488d333371f121f3aefc989ba1270ee:/services/templateservice.php diff --git a/services/templateservice.php b/services/templateservice.php index 191ab8d..1a1719c 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 TemplateService() { + $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 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); + } } -?> \ No newline at end of file