<?php
class Tree
{
public $siteName;
protected static $instance;
protected function __construct($siteName)
{
$this->siteName=$siteName;
}
//获取本类的唯一实例
public static function getInstance ($siteName="dream698")
{
if(!self::$instance instanceof self)
{
self::$instance =new self('www.feichengs.com');
}
return self::$instance;
}
}
//使用工厂函数生成类
class Factory
{
public static function create()
{
return Tree::getInstance();
}
}
//使用注册树注册类
class Register
{
public static $objects=[];
//往注册树上挂
public static function set($alias,$obj)
{
self::$objects[$alias]=$obj;
}
//获取注册树的对象
public static function get($alias)
{
return self::$objects[$alias];
}
//销毁注册时
public static function destroy($alias)
{
unset($objects[$alias]);
}
}
Register::set("site",Factory::create());
$obj=Register::get('site');
var_dump($obj);
?>