| 1 | <?php |
||
| 10 | trait Session |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Session |
||
| 14 | * @var array|\ArrayObject |
||
| 15 | */ |
||
| 16 | protected $session; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Flash message |
||
| 20 | * @var Flash |
||
| 21 | */ |
||
| 22 | protected $flash; |
||
| 23 | |||
| 24 | |||
| 25 | /** |
||
| 26 | * Get request, set for controller |
||
| 27 | * |
||
| 28 | * @return ServerRequestInterface |
||
| 29 | */ |
||
| 30 | abstract public function getRequest(); |
||
| 31 | |||
| 32 | |||
| 33 | /** |
||
| 34 | * Link the session to the session property in the controller |
||
| 35 | */ |
||
| 36 | 2 | public function useSession() |
|
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * Get an/or set the flash message. |
||
| 48 | * |
||
| 49 | * @param mixed $type flash type, eg. 'error', 'notice' or 'success' |
||
| 50 | * @param mixed $message flash message |
||
| 51 | * @return Flash |
||
| 52 | */ |
||
| 53 | 2 | public function flash($type = null, $message = null) |
|
| 65 | } |
||
| 66 |
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: