af1b8e74e4c06afd9e56b72f315670579014a516
[pharext/pharext.org] / app / Session.php
1 <?php
2
3 namespace app;
4
5 use ArrayAccess;
6 use http\Env\Response;
7 use http\Params;
8
9 class Session implements ArrayAccess
10 {
11 function __construct(Config $config, BaseUrl $baseUrl, Response $response) {
12 ini_set("session.cookie_path", $baseUrl->path);
13 foreach ($config->session as $key => $val) {
14 ini_set("session.$key", $val);
15 }
16 if (ini_get("session.use_cookies")) {
17 $response->addHeader("Vary", "cookie");
18 }
19 $response->addHeader("Cache-Control",
20 new Params([
21 "private" => true,
22 "must-revalidate" => true,
23 "max-age" => ini_get("session.cache_expire") * 60
24 ])
25 );
26 session_start();
27 }
28
29 function regenerateId() {
30 session_regenerate_id();
31 return $this;
32 }
33
34 function reset() {
35 $_SESSION = array();
36 session_destroy();
37 return $this;
38 }
39
40 function __debugInfo() {
41 return $_SESSION;
42 }
43
44 function &__get($p) {
45 return $_SESSION[$p];
46 }
47 function &offsetGet($o) {
48 return $_SESSION[$o];
49 }
50 function __set($p, $v) {
51 $_SESSION[$p] = $v;
52 }
53 function offsetSet($o, $v) {
54 $_SESSION[$o] = $v;
55 }
56 function __isset($p) {
57 return isset($_SESSION[$p]);
58 }
59 function offsetExists($o) {
60 return isset($_SESSION[$o]);
61 }
62 function __unset($p) {
63 unset($_SESSION[$p]);
64 }
65 function offsetUnset($o) {
66 unset($_SESSION[$o]);
67 }
68
69 }