Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Registry
- {
- /**
- * Static instance
- *
- * @var Registry
- */
- private static $_instance;
- /**
- * Object hash map
- *
- * @var array
- */
- private $_map;
- /**
- * Private constructor
- *
- */
- private function __construct()
- {}
- /**
- * Get the single instance
- *
- * @return Registry
- */
- public static function getInstance()
- {
- if(self::$_instance === null)
- {
- //First and only construction.
- self::$_instance = new self();
- }
- return self::$_instance;
- }
- /**
- * Get an object by key
- *
- * @param string|int $key
- * @return object
- */
- public function get($key)
- {
- return $this->_map[$key];
- }
- /**
- * Set an object by key
- *
- * @param string|int $key
- */
- public function set($key, $object)
- {
- return $this->_map[$key] = $object;
- }
- /**
- * Disallow cloning
- *
- */
- private function __clone()
- {}
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement