Permalink
Browse files

Proper singleton pattern for Template class

  • Loading branch information...
1 parent d52a871 commit f3f1a78b9a173dae2d64243b67ae819e8c45147b Joni committed Oct 27, 2012
Showing with 22 additions and 10 deletions.
  1. +12 −6 environment/classes/template/Template.class.php
  2. +10 −4 public/install/library/classes/Template.class.php
@@ -10,6 +10,13 @@
* @http://www.projectpier.org/
*/
class Template {
+
+ /**
+ * Class instance
+ *
+ * @var Object
+ */
+ private static $_instance;
/**
* Array of template variables
@@ -87,12 +94,11 @@ function includeTemplate($template) {
* @param void
* @return Template
*/
- function instance() {
- static $instance;
- if (!instance_of($instance, 'Template')) {
- $instance = new Template();
- } // if
- return $instance;
+ static function instance() {
+ if(!isset(self::$_instance)) {
+ self::$_instance = new self;
+ }
+ return self::$_instance;
} // instance
} // Template
@@ -10,6 +10,13 @@
* @http://www.projectpier.org/
*/
class Template {
+
+ /**
+ * Class instance
+ *
+ * @var Object
+ */
+ private static $_instance;
/**
* Array of template variables
@@ -84,11 +91,10 @@ function includeTemplate($template) {
* @return Template
*/
static function instance() {
- static $instance;
- if (!($instance instanceof Template)) {
- $instance = new Template();
+ if(!isset(self::$_instance)) {
+ self::$_instance = new self;
}
- return $instance;
+ return self::$_instance;
} // instance
} // Template

0 comments on commit f3f1a78

Please sign in to comment.