| 1 | <?php |
||
| 6 | class Auth implements AuthInterface |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @var StorageInterface |
||
| 10 | */ |
||
| 11 | protected $storage; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var string|int|null |
||
| 15 | */ |
||
| 16 | protected $id; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var Authenticatable|null |
||
| 20 | */ |
||
| 21 | protected $user; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var UserRepository |
||
| 25 | */ |
||
| 26 | protected $repository; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Auth constructor. |
||
| 30 | * @param StorageInterface $storage |
||
| 31 | * @param UserRepository $repository |
||
| 32 | */ |
||
| 33 | 7 | public function __construct(StorageInterface $storage, UserRepository $repository) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * @return bool |
||
| 41 | */ |
||
| 42 | 7 | public function loggedIn() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @return Authenticatable|null |
||
| 55 | * @throws \RuntimeException |
||
| 56 | */ |
||
| 57 | 3 | public function user() |
|
| 64 | |||
| 65 | /** |
||
| 66 | * @return int|string|null |
||
| 67 | */ |
||
| 68 | 2 | public function getUserId() |
|
| 69 | { |
||
| 70 | 2 | if (!$this->loggedIn()) { |
|
| 71 | 1 | return null; |
|
| 72 | } |
||
| 73 | 1 | return $this->id; |
|
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param Authenticatable $user |
||
| 78 | */ |
||
| 79 | 2 | public function login(Authenticatable $user) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Logs out user |
||
| 88 | */ |
||
| 89 | 1 | public function logout() |
|
| 95 | } |
||
| 96 |