KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
The following code is from a tutorial ( http://net.tutsplus.com/php/creating-a-php5-framework-part-1/ ), not mine. I have a few questions about this code... The article claims it is using the "registry design pattern"; is that the universal name for this design in the industry? Is there another similar patter out there that would be a better option? Is this pattern considered to be good practice to implement in the context of an MVC framework? I just want to figure out if I should use this design pattern in my own implementation of a MVC framework. Thanks! <?php /** * The PCARegistry object * Implements the Registry and Singleton design patterns * @version 0.1 * @author Michael Peacock */ class PCARegistry { /** * Our array of objects * @access private */ private static $objects = array(); /** * Our array of settings * @access private */ private static $settings = array(); /** * The frameworks human readable name * @access private */ private static $frameworkName = 'PCA Framework version 0.1'; /** * The instance of the registry * @access private */ private static $instance; /** * Private constructor to prevent it being created directly * @access private */ private function __construct() { } /** * singleton method used to access the object * @access public * @return */ public static function singleton() { if( !isset( self::$instance ) ) { $obj = __CLASS__; self::$instance = new $obj; } return self::$instance; } /** * prevent cloning of the object: issues an E_USER_ERROR if this is attempted */ public function __clone() { trigger_error( 'Cloning the registry is not permitted', E_USER_ERROR ); } /** * Stores an object in the registry * @param String $object the name of the object * @param String $key the key for the array * @ret
Tags (comma-separated)
Save Edits
Cancel