|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace FSi\Bundle\AdminSecurityBundle\Doctrine\Admin; |
|
13
|
|
|
|
|
14
|
|
|
use FSi\Bundle\AdminBundle\Doctrine\Admin\BatchElement; |
|
15
|
|
|
use FSi\Bundle\AdminSecurityBundle\Event\ActivationEvent; |
|
16
|
|
|
use FSi\Bundle\AdminSecurityBundle\Event\AdminSecurityEvents; |
|
17
|
|
|
use FSi\Bundle\AdminSecurityBundle\Security\User\ActivableInterface; |
|
18
|
|
|
use RuntimeException; |
|
19
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
20
|
|
|
|
|
21
|
|
|
final class ResendActivationTokenBatchElement extends BatchElement |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
private $userModel; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var EventDispatcherInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $eventDispatcher; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct(EventDispatcherInterface $eventDispatcher, string $userModel, array $options) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct($options); |
|
36
|
|
|
|
|
37
|
|
|
$this->userModel = $userModel; |
|
38
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getId(): string |
|
42
|
|
|
{ |
|
43
|
|
|
return 'admin_security_reset_activation_token'; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getClassName(): string |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->userModel; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param ActivableInterface $object |
|
53
|
|
|
*/ |
|
54
|
|
|
public function apply($object): void |
|
55
|
|
|
{ |
|
56
|
|
|
if (false === $object instanceof ActivableInterface) { |
|
57
|
|
|
throw new RuntimeException(sprintf( |
|
58
|
|
|
'Expected an instance of "%s", got "%s" instead.', |
|
59
|
|
|
ActivableInterface::class, |
|
60
|
|
|
true === is_object($object) ? get_class($object) : gettype($object) |
|
61
|
|
|
)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (true === $object->isEnabled()) { |
|
65
|
|
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->eventDispatcher->dispatch( |
|
69
|
|
|
AdminSecurityEvents::RESEND_ACTIVATION_TOKEN, |
|
|
|
|
|
|
70
|
|
|
new ActivationEvent($object) |
|
|
|
|
|
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|