Permalink
Browse files

Merge pull request #27 from noxstyle/master

Proper singleton pattern for Template class
  • Loading branch information...
phpfreak committed Nov 14, 2012
2 parents d52a871 + f3f1a78 commit 6bf887c636c7853350999b55151747f3f342a009
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 6bf887c

Please sign in to comment.