-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsersFacadeForProductivity.php
62 lines (53 loc) · 1.51 KB
/
UsersFacadeForProductivity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* This file is part of the todocler package.
*
* (C) Alan Gabriel Bem <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Users\Infrastructure;
use Productivity;
use Streak\Application\QueryBus;
use Users\Application\Projector\RegisteredUsers\Doctrine\Entity\RegisteredUser;
use Users\Application\Query\FindUser;
use Users\Application\Query\IsUserRegistered;
/**
* @author Alan Gabriel Bem <[email protected]>
*
* @see \Users\Infrastructure\UsersFacadeForProductivityTest
*/
final class UsersFacadeForProductivity implements Productivity\UsersFacade
{
public function __construct(private QueryBus $bus)
{
}
public function isUserRegistered(string $email) : bool
{
try {
return $this->bus->dispatch(new IsUserRegistered($email));
} catch (\Throwable) {
// projection does not exist yet
return false;
}
}
public function findRegisteredUser(string $email) : ?object
{
try {
/** @var ?RegisteredUser $user */
$user = $this->bus->dispatch(new FindUser($email));
} catch (\Throwable) {
// projection does not exists yet
return null;
}
if (null === $user) {
return null;
}
return (object) [
'id' => $user->getId(),
'email' => $user->getEmail(),
];
}
}