1 | <?php |
||
12 | class UserRepository |
||
13 | { |
||
14 | /** |
||
15 | * Database table name that this repository maintains. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public const TABLE = 'user'; |
||
20 | |||
21 | /** |
||
22 | * @var Connection |
||
23 | */ |
||
24 | private $connection; |
||
25 | /** |
||
26 | * @var SecurityRolesRepository |
||
27 | */ |
||
28 | private $securityRolesRepository; |
||
29 | |||
30 | public function __construct(Connection $connection, SecurityRolesRepository $securityRolesRepository) |
||
35 | |||
36 | /** |
||
37 | * Fetches all users. |
||
38 | * |
||
39 | * @throws RecordsNotFoundException Thrown when no records are found |
||
40 | * @return UserEntity[] |
||
41 | */ |
||
42 | public function fetchAll(): array |
||
57 | |||
58 | /** |
||
59 | * Fetches a user by its id. |
||
60 | * |
||
61 | * @throws RecordNotFoundException Thrown when the request record is not found |
||
62 | */ |
||
63 | public function fetchOneById(int $id): UserEntity |
||
83 | |||
84 | /** |
||
85 | * Fetches a user by its username. |
||
86 | * |
||
87 | * @throws RecordNotFoundException Thrown when the request record is not found |
||
88 | */ |
||
89 | public function fetchOneByUsername(string $username): UserEntity |
||
113 | |||
114 | /** |
||
115 | * Creates a user in the database. |
||
116 | * |
||
117 | * @throws RecordAlreadyExistsException |
||
118 | */ |
||
119 | public function create(UserEntity $entity): UserEntity |
||
136 | |||
137 | /** |
||
138 | * Update a user in the database. |
||
139 | * |
||
140 | * @throws RecordNotPersistedException |
||
141 | */ |
||
142 | public function update(UserEntity $entity): UserEntity |
||
160 | |||
161 | /** |
||
162 | * Removes a user from the database. |
||
163 | * |
||
164 | * @throws RecordNotPersistedException |
||
165 | */ |
||
166 | public function remove(UserEntity $entity): UserEntity |
||
181 | |||
182 | /** |
||
183 | * Converts database array to entity array. |
||
184 | * |
||
185 | * @return UserEntity[] |
||
186 | */ |
||
187 | private function getEntityArrayFromDatabaseArray(array $result): array |
||
197 | |||
198 | /** |
||
199 | * Maps the given entity to the database array. |
||
200 | */ |
||
201 | public function getDatabaseArrayFromEntity(UserEntity $entity): array |
||
217 | |||
218 | /** |
||
219 | * Prepares database array from properties. |
||
220 | */ |
||
221 | public function getEntityFromDatabaseArray(array $data): UserEntity |
||
238 | } |
||
239 |