Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
Registry pattern class - PHP Code Bank
Registry pattern class
My implementation of a Registry class.
Instead of using Factory patterns for classes to be loaded it instead takes arguments.
// The Reflection API was introduced in the release of PHP5, thus it's not available for PHP 4 or lower.
class Registry
{
// Private numb constructor makes us unable to instantiate this class.
private function __construct(){}
// Same goes for cloning.
private function __clone(){}
// Our function to fetch our instance, if it doesn't exist then it also creates it.
public function getInstance($className)
{
static $instances = array();
if (!array_key_exists($className, $instances) {
$argArray = func_get_args();
array_shift($argArray);
$reflectionObj = new ReflectionClass($className);
$instances[$className] = $reflectionObj->newInstanceArgs($argArray);
unset($reflectionObj);
}
$instance =& $instances[$className];
return $instance;
}
}
// Now a new object can be created like: $newObject = Registry::getInstance('ClassName', $arg1, $arg2, $arg3);
Comments
Sorry but there are no comments to display