Hookr_Singleton::get_instance PHP Метод

get_instance() защищенный статический Метод

Returns the singleton instance.
protected static get_instance ( string $class = __CLASS__ ) : string
$class string
Результат string
    protected static function get_instance($class = __CLASS__)
    {
        if (__CLASS__ === $class) {
            throw new Exception(__METHOD__ . ' must be overridden');
        }
        if (null === self::$_instances) {
            self::$_instances = array();
        }
        if (@isset(self::$_instances[$class])) {
            return self::$_instances[$class];
        }
        self::$_instances[$class] = new $class();
        $instance = self::$_instances[$class];
        return $instance;
    }

Usage Example

Пример #1
0
 /**
  * Returns the Hookr_Plugin derived instance.
  * 
  * @static
  * @access protected
  * @param string $class
  * @return object Instance of Hookr_Plugin
  */
 protected static function get_instance($class = __CLASS__)
 {
     $instance = parent::get_instance($class);
     add_action('plugins_loaded', array($instance, 'load'), 0);
     add_action('init', array($instance, 'loaded'), 0);
     if (is_admin()) {
         $file = $instance->get_file();
         register_activation_hook($file, array($instance, 'activate'));
         register_deactivation_hook($file, array($instance, 'deactivate'));
     }
     return $instance;
 }