1 | <?php |
||
17 | class Pdo extends Storage implements Cleanable |
||
18 | { |
||
19 | /** |
||
20 | * @var \Pimf\Database |
||
21 | */ |
||
22 | protected $pdo; |
||
23 | |||
24 | /** |
||
25 | * @param \Pimf\Database $pdo |
||
26 | */ |
||
27 | public function __construct(\Pimf\Database $pdo) |
||
31 | |||
32 | /** |
||
33 | * Load a session from storage by a given ID. |
||
34 | * If no session is found for the ID, null will be returned. |
||
35 | * |
||
36 | * @param string $key |
||
37 | * |
||
38 | * @return array|null |
||
39 | */ |
||
40 | public function load($key) |
||
41 | { |
||
42 | try { |
||
43 | $sth = $this->pdo->prepare( |
||
44 | 'SELECT * FROM sessions WHERE id = :id' |
||
45 | ); |
||
46 | |||
47 | $sth->bindValue(':id', $key, \PDO::PARAM_INT); |
||
48 | $sth->execute(); |
||
49 | |||
50 | $session = $sth->fetchObject(); |
||
51 | |||
52 | if ($session instanceof \stdClass) { |
||
53 | return array( |
||
54 | 'id' => $session->id, |
||
55 | 'last_activity' => $session->last_activity, |
||
56 | 'data' => unserialize($session->data) |
||
57 | ); |
||
58 | } |
||
59 | |||
60 | return null; |
||
61 | } catch (\PDOException $pdoe) { |
||
62 | return null; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Save a given session to storage. |
||
68 | * |
||
69 | * @param array $session |
||
70 | * @param array $config |
||
71 | * @param bool $exists |
||
72 | */ |
||
73 | public function save($session, $config, $exists) |
||
90 | |||
91 | /** |
||
92 | * Delete a session from storage by a given ID. |
||
93 | * |
||
94 | * @param string $key |
||
95 | */ |
||
96 | public function delete($key) |
||
105 | |||
106 | /** |
||
107 | * Delete all expired sessions from persistent storage. |
||
108 | * |
||
109 | * @param int $expiration |
||
110 | * |
||
111 | * @return mixed|void |
||
112 | */ |
||
113 | public function clean($expiration) |
||
122 | } |
||
123 |