<?php
abstract class Registry{
abstract protected function set($key,$value);
abstract protected function get($key);
}
class RequestRegistry extends Registry{
private static $instance;
private $values=array();
static function instance(){
if(!isset(self::$instance)){
self::$instance=new self();
}
return self::$instance;
}
protected function set($key,$value){
$this->values[$key]=$value;
}
protected function get($key){
return $this->values[$key];
}
function getAaa(){
return self::instance()->get('Aaa');
}
function setAaa($aaa){
self::instance()->set("Aaa",$aaa);
}
}
class SessionRegistry extends Registry{
private static $instance;
private $values=array();
static function instance(){
if(!isset(self::$instance)){
self::$instance=new self();
}
return self::$instance;
}
protected function set($key,$val){
$this->values[$key]=$val;
}
protected function get($key){
return $this->values[$key];
}
function getBbb($key){
return self::instance()->get($key);
}
function setBbb($key,$val){
self::instance()->set($key,$val);
}
}
class reg{}
$re=SessionRegistry::instance();
$re->setBbb('Bbb',new reg());
print_r($re->getBbb('Bbb'));
$ss=RequestRegistry::instance();
$ss->setAaa('aaa');
echo $ss->getAaa('Aaa');
?>
|