1 | <?php |
||
13 | class PhpSession |
||
14 | { |
||
15 | use Utils\StorageTrait; |
||
16 | |||
17 | const STORAGE_KEY = 'PHP_SESSION_STORAGE'; |
||
18 | |||
19 | /** |
||
20 | * @var string|null |
||
21 | */ |
||
22 | private $name; |
||
23 | |||
24 | /** |
||
25 | * @var string|null |
||
26 | */ |
||
27 | private $id; |
||
28 | |||
29 | /** |
||
30 | * Constructor. Defines de session name. |
||
31 | * |
||
32 | * @param null|string $name |
||
33 | */ |
||
34 | public function __construct($name = null) |
||
40 | |||
41 | /** |
||
42 | * Configure the session name. |
||
43 | * |
||
44 | * @param string $name |
||
45 | * |
||
46 | * @return self |
||
47 | */ |
||
48 | public function name($name) |
||
54 | |||
55 | /** |
||
56 | * Configure the session id. |
||
57 | * |
||
58 | * @param string $id |
||
59 | * |
||
60 | * @return self |
||
61 | */ |
||
62 | public function id($id) |
||
68 | |||
69 | /** |
||
70 | * Execute the middleware. |
||
71 | * |
||
72 | * @param ServerRequestInterface $request |
||
73 | * @param ResponseInterface $response |
||
74 | * @param callable $next |
||
75 | * |
||
76 | * @return ResponseInterface |
||
77 | */ |
||
78 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
119 | } |
||
120 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: