X-Git-Url: https://projects.mako.cc/source/scuttle/blobdiff_plain/bce919af7b49bbd06223f79b8c37a53a3d263ff0..c7f63c8b9b12efd7b3c10b9f80cda06eaf32068f:/services/templateservice.php?ds=inline 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