*/ class struct_subject_cgi { /** * @var string * @author Christian Fraß */ public $id; /** * @param string $id * @author Christian Fraß */ public function __construct( string $id ) { $this->id = $id; } } /** * @param struct_subject_cgi $subject * @param string $key * @throw \Exception if no such key * @author Christian Fraß */ function _cgi_keycheck( struct_subject_cgi $subject, string $key ) : void { // \session_id($subject->id); if (! array_key_exists($key, $_SESSION)) { $message = sprintf('no key "%s"', $key); throw (new \Exception($message)); } } /** * @author Christian Fraß */ function cgi_set_dir( string $path ) : void { ini_set('session.save_path', $path); } /** * @author Christian Fraß */ function cgi_begin( ) : struct_subject_cgi { \session_start(); $id = \session_id(); $subject = new struct_subject_cgi($id); return $subject; } /** * @author Christian Fraß */ function cgi_get( string $id ) : struct_subject_cgi { $subject = (new struct_subject_cgi($id)); \session_id($id); \session_start(); return $subject; } /** * @author Christian Fraß */ function cgi_id( struct_subject_cgi $subject ) : string { return $subject->id; } /** * @implementation * @author Christian Fraß */ function cgi_read( struct_subject_cgi $subject, string $key ) : string { _cgi_keycheck($subject, $key); // \session_id($subject->id); $value = $_SESSION[$key]; return $value; } /** * @implementation * @author Christian Fraß */ function cgi_write( struct_subject_cgi $subject, string $key, string $value ) : void { // \session_id($subject->id); $_SESSION[$key] = $value; } /** * @implementation * @author Christian Fraß */ function cgi_remove( struct_subject_cgi $subject, string $key ) : void { _cgi_keycheck($subject, $key); // \session_id($subject->id); unset($_SESSION[$key]); } /** * @implementation * @author Christian Fraß */ function cgi_end( struct_subject_cgi $subject ) : void { // \session_id($subject->id); \session_destroy(); } /** * @author Christian Fraß */ class implementation_cgi implements interface_session { /** * @var struct_subject_cgi * @author Christian Fraß */ private $subject; /** * @author Christian Fraß */ private function __construct(struct_subject_cgi $subject) {$this->subject = $subject;} /** * implementations * * @author Christian Fraß */ public static function begin() : interface_session {return (new implementation_cgi(cgi_begin()));} public static function get(string $id) : interface_session {return (new implementation_cgi(cgi_get($id)));} public function id() : string {return cgi_id($this->subject);} public function read(string $key) : string {return cgi_read($this->subject, $key);} public function write(string $key, string $value) : void {cgi_write($this->subject, $key, $value);} public function remove(string $key) : void {cgi_remove($this->subject, $key);} public function end() : void {cgi_end($this->subject);} } ?>