implement find by email in json user repo
This commit is contained in:
parent
64edec5141
commit
ac461afcf0
1 changed files with 17 additions and 0 deletions
|
|
@ -50,6 +50,23 @@ class JsonUserRepository implements UserRepository
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function findByEmail(EmailAddress $email): ?User
|
||||||
|
{
|
||||||
|
$users = $this->readUsers();
|
||||||
|
|
||||||
|
foreach ($users as $data) {
|
||||||
|
if ($data['email'] === (string) $email) {
|
||||||
|
return new User(
|
||||||
|
id: $data['id'],
|
||||||
|
email: new EmailAddress($data['email']),
|
||||||
|
isAdmin: $data['isAdmin'] ?? false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private function readUsers(): array
|
private function readUsers(): array
|
||||||
{
|
{
|
||||||
if (!file_exists($this->filePath)) {
|
if (!file_exists($this->filePath)) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue