|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Palladium\Service; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Class for finding indentities based on various conditions |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
use Palladium\Mapper as Mapper; |
|
11
|
|
|
use Palladium\Entity as Entity; |
|
12
|
|
|
use Palladium\Exception\UserNotFound; |
|
13
|
|
|
use Palladium\Exception\IdentityNotFound; |
|
14
|
|
|
use Palladium\Exception\TokenNotFound; |
|
15
|
|
|
|
|
16
|
|
|
use Palladium\Contract\CanCreateMapper; |
|
17
|
|
|
use Psr\Log\LoggerInterface; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
class Search |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
private $mapperFactory; |
|
24
|
|
|
private $logger; |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
4 |
|
public function __construct(CanCreateMapper $mapperFactory, LoggerInterface $logger) |
|
28
|
|
|
{ |
|
29
|
4 |
|
$this->mapperFactory = $mapperFactory; |
|
30
|
4 |
|
$this->logger = $logger; |
|
31
|
4 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
2 |
|
public function findEmailIdenityByIdentifier($identifier) |
|
35
|
|
|
{ |
|
36
|
2 |
|
$identity = new Entity\EmailIdentity; |
|
37
|
2 |
|
$identity->setIdentifier($identifier); |
|
38
|
|
|
|
|
39
|
2 |
|
$mapper = $this->mapperFactory->create(Mapper\EmailIdentity::class); |
|
40
|
2 |
|
$mapper->fetch($identity); |
|
41
|
|
|
|
|
42
|
2 |
|
if ($identity->getId() === null) { |
|
43
|
1 |
|
$this->logger->warning('acount not found', [ |
|
44
|
|
|
'input' => [ |
|
45
|
1 |
|
'identifier' => $identifier, |
|
46
|
|
|
], |
|
47
|
|
|
]); |
|
48
|
|
|
|
|
49
|
1 |
|
throw new IdentityNotFound; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
return $identity; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
1 |
|
public function findEmailIdenityByToken($token, $action = Entity\Identity::ACTION_ANY) |
|
57
|
|
|
{ |
|
58
|
1 |
|
$identity = new Entity\EmailIdentity; |
|
59
|
|
|
|
|
60
|
1 |
|
$identity->setToken($token); |
|
61
|
1 |
|
$identity->setTokenAction($action); |
|
62
|
1 |
|
$identity->setTokenEndOfLife(time()); |
|
63
|
|
|
|
|
64
|
1 |
|
$mapper = $this->mapperFactory->create(Mapper\Identity::class); |
|
65
|
1 |
|
$mapper->fetch($identity); |
|
66
|
|
|
|
|
67
|
1 |
|
return $identity; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
1 |
|
public function findCookieIdenity($userId, $series) |
|
72
|
|
|
{ |
|
73
|
1 |
|
$cookie = new Entity\CookieIdentity; |
|
74
|
1 |
|
$cookie->setStatus(Entity\Identity::STATUS_ACTIVE); |
|
75
|
1 |
|
$cookie->setUserId($userId); |
|
76
|
1 |
|
$cookie->setSeries($series); |
|
77
|
|
|
|
|
78
|
1 |
|
$mapper = $this->mapperFactory->create(Mapper\CookieIdentity::class); |
|
79
|
1 |
|
$mapper->fetch($cookie); |
|
80
|
|
|
|
|
81
|
1 |
|
return $cookie; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|