1 | <?php |
||
2 | namespace MyWonderland\Domain\Manager; |
||
3 | |||
4 | /** |
||
5 | * Created by PhpStorm. |
||
6 | * User: thiago |
||
7 | * Date: 01/04/18 |
||
8 | * Time: 10:56 |
||
9 | */ |
||
10 | |||
11 | /** |
||
12 | * Class SessionManager |
||
13 | * @package MyWonderland\Domain\Manager |
||
14 | * |
||
15 | * (from PHP docs): Caution -- If you turn on session.auto_start then the only way to put objects |
||
16 | * into your sessions is to load its class definition using auto_prepend_file in which you load |
||
17 | * the class definition else you will have to serialize() your object and unserialize() it afterwards. |
||
18 | * http://php.net/manual/en/intro.session.php |
||
19 | */ |
||
20 | class SessionManager implements StorageManager |
||
21 | { |
||
22 | // @todo improve security |
||
23 | function __construct() |
||
0 ignored issues
–
show
|
|||
24 | { |
||
25 | session_start(); |
||
26 | } |
||
27 | |||
28 | function set($key, $value) |
||
0 ignored issues
–
show
|
|||
29 | { |
||
30 | $_SESSION[$key] = serialize($value); |
||
31 | } |
||
32 | |||
33 | function get($key) |
||
0 ignored issues
–
show
|
|||
34 | { |
||
35 | return unserialize($_SESSION[$key]); |
||
36 | } |
||
37 | |||
38 | function has($key) |
||
0 ignored issues
–
show
|
|||
39 | { |
||
40 | return isset($_SESSION[$key]); |
||
41 | } |
||
42 | |||
43 | function unset($key) |
||
44 | { |
||
45 | unset($_SESSION[$key]); |
||
46 | } |
||
47 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.