add flat file impl with find by email, save not implemented yet
This commit is contained in:
parent
7d21ce97e9
commit
a64a2103e1
1 changed files with 23 additions and 0 deletions
23
src/User/FlatFileUserRepository.php
Normal file
23
src/User/FlatFileUserRepository.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FreightQuote\User;
|
||||||
|
|
||||||
|
class FlatFileUserRepository implements UserRepository
|
||||||
|
{
|
||||||
|
private string $pathToUserFile = __DIR__.'/../../storage/users.json';
|
||||||
|
|
||||||
|
public function findByEmail(string $email): ?User
|
||||||
|
{
|
||||||
|
$json = file_get_contents($this->pathToUserFile);
|
||||||
|
$data = json_decode($json, true);
|
||||||
|
foreach ($data as $user) {
|
||||||
|
if ($user['email'] === $email) {
|
||||||
|
return new User($user['email'], $user['password']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(User $user): User
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue