Example #1
0
 public static function getInstance()
 {
     if (!static::$inst) {
         static::$inst = static::createInstance();
     }
     return static::$inst;
 }
 /**
  *  Dynamicly map static function calls to dynamic methods the 
  *  class defined in parent::$class_name 
  */
 public static function __callStatic($name, $args)
 {
     if (!is_object(static::$inst)) {
         $inst = static::$inst = static::get_instance();
     } else {
         $inst = static::$inst;
     }
     if (is_callable(array($inst, $name))) {
         return call_user_func_array(array($inst, $name), $args);
     } else {
         throw new Exception($name . " not implemented by " . static::$class_name);
     }
 }
Example #3
0
 static function get_instance($config = NULL, $db = NULL)
 {
     //some objects are global and need parameters these are constructed using
     //a stranded constructor and need parameters passing. if they have not been
     //built and get_instance is call it should return null
     if (isset(static::$dont_construct) and static::$dont_construct == true) {
         if (is_object(static::$inst)) {
             return static::$inst;
         } else {
             return NULL;
         }
     }
     //normal behaviour create on demand
     if (!is_object(static::$inst) and $config != NULL and $db != NULL) {
         static::$inst = new static::$class_name($config, $db);
     }
     if ($config == NULL or $db == NULL) {
         return NULL;
     }
     return static::$inst;
 }
Example #4
0
 /**
  * For init new instance of other class (parent vs child) - we need destroy old instance class (destroy instance of singleton)
  */
 public function destroy()
 {
     static::$inst = null;
 }
Example #5
0
 /**
  * Pattern Singleton.
  *
  * @param AppConfiguration $config
  * @param Request $request
  * @param Response $response
  * @return Application
  */
 public static function make(AppConfiguration $config, Request $request, Response $response)
 {
     if (static::$inst === null) {
         static::$inst = new static($config, $request, $response);
     }
     return static::$inst;
 }
Example #6
0
 /**
  * sets the Mock instance to return. ONLY used for unit testing
  *
  */
 public static function set_mock_instance($obj)
 {
     static::$inst = $obj;
 }