CHAPTER 12 ■ ENTERPRISE PATTERNS
if ( isset( $this->values[$key] ) ) {
return $this->values[$key];
}
return null;
}
protected function set( $key, $val ) {
$this->values[$key] = $val;
}
static function getRequest() {
return self::instance()->get('request');
}
static function setRequest( \woo\controller\Request $request ) {
return self::instance()->set('request', $request );
}
}
The session-level implementation simply uses PHP’s built-in session support:
namespace woo\base;
// ...
class SessionRegistry extends Registry {
private static $instance;
private function __construct() {
session_start();
}
static function instance() {
if (! isset(self::$instance) ) { self::$instance = new self(); }
return self::$instance;
}
protected function get( $key ) {
if ( isset( $_SESSION[CLASS][$key] ) ) {
return $_SESSION[CLASS][$key];
}
return null;
}
protected function set( $key, $val ) {
$_SESSION[CLASS][$key] = $val;
}
function setComplex( Complex $complex ) {
self::instance()->set('complex', $complex);
}
function getComplex( ) {
return self::instance()->get('complex');
}
}