I have written a registry class before, but that one cannot be registered with multiple classes, and the following arrays are used to store the class.
Copy the Code code as follows:
Basic class
Class WebSite {//a very simple base class
Private $siteName;
Private $SITEURL;
function __construct ($siteName, $SITEURL) {
$this->sitename= $siteName;
$this->siteurl= $siteUrl;
}
function GetName () {
return $this->sitename;
}
function GetUrl () {
return $this->siteurl;
}
}
Class Registry {//Registry class Singleton mode
private static $instance;
Private $values =array ();//Use an array to hold the class name
Private Function __construct () {}//This usage determines that the class cannot be instantiated directly
static function instance () {
if (!isset (self:: $instance)) {self:: $instance =new self ();}
Return self:: $instance;
}
function Get ($key) {//Get a class that has already been registered
if (Isset ($this->values[$key])) {
return $this->values[$key];
}
return null;
}
function set ($key, $value) {//Register class method
$this->values[$key]= $value;
}
}
$reg =registry::instance ();
$reg->set ("website", New website ("Web Development note", "www.chhua.com"));//Register the class
$website = $reg->get ("website");//Get Class
echo $website->getname ();//output Web development note
echo $website->geturl ();//Output www.chhua.com
?>
The purpose of the registry is to provide system-level object access functionality. Some students will say, this is superfluous, but the small project does not necessarily need to register the class, if it is a large project, it is very useful.
The above describes the BIOS setup hard disk mode PHP design mode registry mode of the registration of multiple classes, including the BIOS to set the hard disk mode of the content, I hope that the PHP tutorial interested friends helpful.