Created
April 14, 2019 02:00
-
-
Save otanodesignco/11d8722294904b4765c833aca82521e3 to your computer and use it in GitHub Desktop.
php hook system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class hookSystem | |
{ | |
/** | |
* @abstract Objects array | |
* @access Private | |
*/ | |
private static $objects = array(); | |
/** | |
* @abstract Settings array | |
* @access private | |
*/ | |
private static $settings = array(); | |
/** | |
* @abstract The one and only instance allowed. | |
* @access private | |
*/ | |
private static $instance; | |
/** | |
* @abstract Private constructor | |
* @access private | |
*/ | |
private function __construct() | |
{ | |
$this->storeCoreObjects(); | |
} | |
/** | |
* @abstract Store the core framework objects | |
* @access private | |
*/ | |
private function storeCoreObjects() | |
{ | |
//Store objects: $this->storeObject("database","db"); | |
} | |
/** | |
* @abstract Create the instance of the registry | |
* @access public | |
* @return self::instance | |
*/ | |
public static function singleton() | |
{ | |
if (!isset(self::$instance)) { | |
$obj = __class__; | |
self::$instance = new $obj; | |
} | |
return self::$instance; | |
} | |
/** | |
* @abstract Prevent cloning of the registry | |
* @access public | |
*/ | |
public function __clone() | |
{ | |
trigger_error('Cloning the registry is not permitted', E_USER_ERROR); | |
} | |
/** | |
* @abstract Stores an object to the array | |
* @access private | |
* @param String $key | |
* @param String $object | |
* @return void | |
*/ | |
public function storeObject($object, $key) | |
{ | |
require_once ('Objects/' . $object . '.class.php'); | |
self::$objects[$key] = new $object(self::$instance); | |
} | |
/** | |
* @abstract Get an object from the array | |
* @access public | |
* @param String $key | |
* @return object | |
*/ | |
public function getObject($key) | |
{ | |
if (is_object(self::$objects[$key])) { | |
return self::$objects[$key]; | |
} | |
} | |
/** | |
* @abstract Store a setting to the registry | |
* @access public | |
* @param String $data | |
* @param String $key | |
* @return void | |
*/ | |
public function storeSetting($data, $key) | |
{ | |
self::$settings[$key] = $data; | |
} | |
/** | |
* @abstract Get a setting from the registry | |
* @access public | |
* @param String $key | |
* @return Setting | |
*/ | |
public function getSetting($key) | |
{ | |
return self::$settings[$key]; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment