| Total Complexity | 8 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class AuthStorage implements Auth\StorageInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * A list of users. |
||
| 18 | * DO NOT COPY THIS; Use a database to store and fetch the users instead. |
||
| 19 | */ |
||
| 20 | public const USERS = [ |
||
| 21 | [ |
||
| 22 | 'id' => 1, |
||
| 23 | 'username' => 'jackie', |
||
| 24 | 'hashedPassword' => '$2y$10$lVUeiphXLAm4pz6l7lF9i.6IelAqRxV4gCBu8GBGhCpaRb6o0qzUO', // jackie123 |
||
| 25 | 'role' => 1, // user |
||
| 26 | ], |
||
| 27 | [ |
||
| 28 | 'id' => 2, |
||
| 29 | 'username' => 'john', |
||
| 30 | 'hashedPassword' => '$2y$10$RU85KDMhbh8pDhpvzL6C5.kD3qWpzXARZBzJ5oJ2mFoW7Ren.apC2', // john123 |
||
| 31 | 'role' => 10, // admin |
||
| 32 | ], |
||
| 33 | ]; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Fetch a user by ID. |
||
| 37 | */ |
||
| 38 | public function fetchUserById(string $id): ?Auth\UserInterface |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Fetch a user by username |
||
| 51 | */ |
||
| 52 | public function fetchUserByUsername(string $username): ?Auth\UserInterface |
||
| 53 | { |
||
| 54 | foreach (self::USERS as $user) { |
||
| 55 | if ($user['username'] === $username) { |
||
| 56 | return BasicUser::fromData($user); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | return null; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Fetch the context by ID. |
||
| 65 | */ |
||
| 66 | public function fetchContext(string $id) : ?Auth\ContextInterface |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get the default context of the user. |
||
| 74 | */ |
||
| 75 | public function getContextForUser(Auth\UserInterface $user) : ?Auth\ContextInterface |
||
| 78 | } |
||
| 79 | } |