| 1 | <?php |
||
| 10 | trait Sessions |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Get the authenticated user |
||
| 14 | * |
||
| 15 | * @return User |
||
| 16 | */ |
||
| 17 | abstract public function user(); |
||
| 18 | |||
| 19 | |||
| 20 | /** |
||
| 21 | * Get the session data |
||
| 22 | * |
||
| 23 | * @return array |
||
| 24 | */ |
||
| 25 | protected function getSessionData($key) |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Update the session |
||
| 32 | * |
||
| 33 | * @param string $key |
||
| 34 | * @param mixed $value |
||
| 35 | */ |
||
| 36 | protected function updateSessionData($key, $value) |
||
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * Get current authenticated user id for the session |
||
| 48 | * |
||
| 49 | * @return mixed |
||
| 50 | */ |
||
| 51 | protected function getCurrentUserId() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Store the current user id in the session |
||
| 58 | */ |
||
| 59 | protected function persistCurrentUser() |
||
| 64 | } |
||
| 65 |
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: