Home  >  Article  >  Backend Development  >  bios set hard disk mode PHP design mode registry mode registration of multiple classes

bios set hard disk mode PHP design mode registry mode registration of multiple classes

WBOY
WBOYOriginal
2016-07-29 08:47:541373browse

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 function of the registry is to provide system-level object access functions. Some students will say that this is unnecessary, but it is indeed not necessary to register classes in small projects. If it is a large project, it is still very useful.

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn