Advertisement
Blade83

Abstract Singleton Class with Params

Mar 10th, 2013
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2. abstract class singleton_array_id_abstract
  3. {
  4.     private static $Instance = array();
  5.     protected static $connID = NULL;
  6.    
  7.     protected function __construct()
  8.     {
  9.     }
  10.    
  11.     public static function getInstance($connID=1)
  12.     {
  13.         self::$connID = $connID;
  14.         $ClassName = get_called_class();
  15.         if(!isset(self::$Instance[$connID][$ClassName]))
  16.         {
  17.             self::$Instance[$connID][$ClassName] = new $ClassName();
  18.         }
  19.         $ObjInstance = self::$Instance[$connID][$ClassName];
  20.         return $ObjInstance;
  21.     }
  22.    
  23.     final private function __clone(){}
  24.    
  25.     final private function __wakeup(){}
  26.    
  27.     final public function get_connID()
  28.     {
  29.             return self::$connID;
  30.         }
  31. }
  32. # class db extends singleton_array_id_abstract {
  33. #   protected function __construct() {
  34. #       $this->ID = $this->get_connID();
  35. #   }
  36. # .....
  37. # }
  38.  
  39. # $db = db::getInstance(SERVER_ID);
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement