BIOS setup HDD mode PHP design mode registry mode registration of multiple classes

Source: Internet
Author: User
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.