All pastes #1340108 Raw Edit

Registry.class.php

public php v1 · immutable
#1340108 ·published 2009-02-17 15:52 UTC
rendered paste body
<?phpif (!defined('__IN_MVC')) {exit();}/** * Registry Class * Implements Overloading and the Singleton design pattern in order to create a central registry * used to store and retrieve references for variables, arrays and objects *  * @access public * @author Rune Vikestad * @copyright 2009 Rune Vikestad * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @package Core * @version 0.0.1 */class Registry {		/**	 * Our registry instance variables as required by the singleton design pattern. Stores 	 * a single instance of the Registry object. 	 * @access protected	 * @staticvar 	 */	protected static $instance;		/**	 * The registry array	 * @var array	 * @access protected	 * @name $registry	 */	protected $registry;		/**	 * Constructor	 * @access protected	 */	protected function __construct() {		$this->registry = array();	}		/**	 * Overloading the __set method, allowing new data to be stored in the registry	 * @access public	 * @return Returns TRUE on success or FALSE on failure	 */	public function __set($key,$data) {		$this->registry[$key] = $data;	}		/**	 * Overloading the __get method, allowing retrieval of data from the registry	 * @access public	 * @return Returns TRUE on success or FALSE on failure	 */	public function __get($key) {		if (array_key_exists($key, $this->registry)) {			return $this->registry[$key];		}		$trace = debug_backtrace();		trigger_error('Undefined property in __get(): ' . $key . ' in ' . $trace[0]['file'] . ' at line ' . $trace[0]['line'], E_USER_NOTICE);		return NULL;	}	/**	 * Overloading the __isset method	 * @access public	 * @return Returns TRUE on success or FALSE on failure	 */	public function __isset($key) {		return isset($this->registry[$key]);	}		/**	 * Overloading the __unset method 	 * @access public	 * @return Returns TRUE on success or FALSE on failure	 */	public function __unset($key) {		if (isset($registry[$key])) {			unset($registry[$key]);			return TRUE;		}		return FALSE;	}		/**	 * @access public	 * @static	 */	public static function getInstance() {        if (!isset(self::$instance)) {            $c = __CLASS__;            self::$instance = new $c;        }        return self::$instance;	}		/**	 * Prevents object cloning	 * @access public	 */    public function __clone() {        trigger_error('Clone is not allowed.', E_USER_ERROR);    }        /**     * Destructor     * @access public     */    public function __destruct() {    	unset($registry);    }}?>