Skip to content

Commit

Permalink
changed pattern to singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Sep 2, 2013
1 parent 4e3c7e3 commit 2d42d92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
19 changes: 17 additions & 2 deletions ClassAutoloader.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
/**
* Autoload needed classes
* @author etessore
* @version 1.0.1
* @version 1.0.2
* @package classes
*/

/*
* Changelog:
* 1.0.2
* rewrited as singleton
* 1.0.1
* support multiple search path to allow children theme to extend classes
* 1.0.0
Expand All @@ -20,6 +22,8 @@
class ClassAutoloader {
const WORDPRESS_THEME_UTILS_CLASS_DIR = 'classes';

private static $instance = null;

/**
* @var array stores the path the system will scan for files
*/
Expand All @@ -28,7 +32,7 @@ class ClassAutoloader {
/**
* Initializes the autoloader
*/
public function __construct() {
private function __construct() {
$this
// First search in the child theme dir
->add_loading_template(
Expand All @@ -45,6 +49,17 @@ public function __construct() {
->register_autoload();
}

/**
* Retrieves the singleton instance
* @return ClassAutoloader
*/
public static function get_instance(){
if(is_null(self::$instance)){
self::$instance = new self;
}
return self::$instance;
}

/**
* Set the loading template
* @param string $tpl the template
Expand Down
2 changes: 1 addition & 1 deletion ThemeUtils.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function get_instance(){
*/
public static function enable_autoload_system(){
include_once WORDPRESS_THEME_UTILS_PATH . WORDPRESS_THEME_UTILS_AUTOLOADER_RELATIVE_PATH;
new ClassAutoloader();
ClassAutoloader::get_instance();
}

/**
Expand Down

0 comments on commit 2d42d92

Please sign in to comment.