Home >Backend Development >PHP Tutorial >bios set hard disk mode PHP design mode registry mode registration of multiple classes
I have also written a registry class before, but that one cannot register multiple classes. The following uses an array to store the classes.
Copy the code The code is as follows:
//Basic class
class webSite {//A very simple basic 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 array to store class name
private function __construct(){}//This usage determines that this class cannot be instantiated directly
static function instance(){
if (!isset(self::$instance)){self::$instance=new self( );}
return self::$instance;
}
function get($key){//Get the registered class
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 Notes","www.chhua.com"));//Configure the class Register
$website=$reg->get("website");//Get the class
echo $website->getName();//Output WEB development notes
echo $website->getUrl();/ /Output www.chhua.com
?>
The above introduces the registration of multiple classes of bios setting hard disk mode, PHP design mode and registry mode, including the content of bios setting hard disk mode. I hope it will be helpful to friends who are interested in PHP tutorials.