add logging; fix caching
[pharext/pharext.org] / app / Github / Storage / Session.php
1 <?php
2
3 namespace app\Github\Storage;
4
5 use app\Github\Storage;
6
7 class Session implements Storage
8 {
9 private $ns;
10
11 function __construct($ns = "github") {
12 $this->ns = $ns;
13 }
14
15 function set($key, Item $item) {
16 $_SESSION[$this->ns][$key] = $item;
17 return $this;
18 }
19
20 function get($key, Item &$item = null, $update = false) {
21 if (!isset($_SESSION[$this->ns][$key])) {
22 return false;
23 }
24 $item = $_SESSION[$this->ns][$key];
25 if (null === $item->getTTL()) {
26 return true;
27 }
28 if ($item->getLTL() >= 0) {
29 if ($update) {
30 $item->setTimestamp();
31 }
32 return true;
33 }
34 return false;
35 }
36
37 function del($key) {
38 unset($_SESSION[$this->ns][$key]);
39 return $this;
40 }
41 }