Created
July 22, 2013 16:54
-
-
Save cmstone/6055518 to your computer and use it in GitHub Desktop.
Registry Pattern Example
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 Registry { | |
private $registry = array(); | |
private static $instance = null; | |
public static function getInstance() { | |
if($this->instance === null) { | |
$this->instance = new Registry(); | |
} | |
return $this->instance; | |
} | |
private function __construct() {} | |
private function __clone() {} | |
public function set($key, $value) { | |
if (isset($this->registry[$key])) { | |
throw new Exception("There is already an entry for key " . $key); | |
} | |
$this->registry[$key] = $value; | |
} | |
public function get($key) { | |
if (!isset($this->registry[$key])) { | |
throw new Exception("There is no entry for key " . $key); | |
} | |
return $this->registry[$key]; | |
} | |
} | |
$mysqli = new mysqli(); | |
$mysqli->connect('localhost', 'luminusm', 'NiX8VWe5', 'luminusm_tedesco'); | |
$registry = Registry::getInstance(); | |
$registry->set('mysqli', $mysqli); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can u please writing the comments of ur codes