1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the BenGorUser package. |
5
|
|
|
* |
6
|
|
|
* (c) Beñat Espiña <[email protected]> |
7
|
|
|
* (c) Gorka Laucirica <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace BenGorUser\User\Domain\Event; |
14
|
|
|
|
15
|
|
|
use BenGorUser\User\Domain\Model\Event\UserEvent; |
16
|
|
|
use BenGorUser\User\Domain\Model\Event\UserRememberPasswordRequested; |
17
|
|
|
use BenGorUser\User\Domain\Model\UserMailableFactory; |
18
|
|
|
use BenGorUser\User\Domain\Model\UserMailer; |
19
|
|
|
use BenGorUser\User\Domain\Model\UserUrlGenerator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* User remember password requested mailer subscriber class. |
23
|
|
|
* |
24
|
|
|
* @author Beñat Espiña <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class UserRememberPasswordRequestedMailerSubscriber implements UserEventSubscriber |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* The mailable factory. |
30
|
|
|
* |
31
|
|
|
* @var UserMailableFactory |
32
|
|
|
*/ |
33
|
|
|
private $mailableFactory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The mailer. |
37
|
|
|
* |
38
|
|
|
* @var UserMailer |
39
|
|
|
*/ |
40
|
|
|
private $mailer; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The url generator. |
44
|
|
|
* |
45
|
|
|
* @var UserUrlGenerator |
46
|
|
|
*/ |
47
|
|
|
private $urlGenerator; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Constructor. |
51
|
|
|
* |
52
|
|
|
* @param UserMailer $aMailer The mailer |
53
|
|
|
* @param UserMailableFactory $aMailableFactory The mailable factory |
54
|
|
|
* @param UserUrlGenerator $anUrlGenerator The url generator |
55
|
|
|
*/ |
56
|
|
|
public function __construct( |
57
|
|
|
UserMailer $aMailer, |
58
|
|
|
UserMailableFactory $aMailableFactory, |
59
|
|
|
UserUrlGenerator $anUrlGenerator |
60
|
|
|
) { |
61
|
|
|
$this->mailer = $aMailer; |
62
|
|
|
$this->mailableFactory = $aMailableFactory; |
63
|
|
|
$this->urlGenerator = $anUrlGenerator; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function handle(UserEvent $anEvent) |
70
|
|
|
{ |
71
|
|
|
$url = $this->urlGenerator->generate( |
72
|
|
|
$anEvent->rememberPasswordToken()->token() |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$mail = $this->mailableFactory->build( |
76
|
|
|
$anEvent->email(), |
77
|
|
|
[ |
78
|
|
|
'email' => $anEvent->email(), |
79
|
|
|
'url' => $url, |
80
|
|
|
] |
81
|
|
|
); |
82
|
|
|
|
83
|
|
|
$this->mailer->mail($mail); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* {@inheritdoc} |
88
|
|
|
*/ |
89
|
|
|
public function isSubscribedTo(UserEvent $anEvent) |
90
|
|
|
{ |
91
|
|
|
return $anEvent instanceof UserRememberPasswordRequested; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|