Completed
Push — master ( 771e5d...491b8d )
by Jeff
02:21
created

DKIMDomainSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the mailserver-admin package.
6
 * (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin>
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace App\Subscriber;
12
13
use App\Entity\Domain;
14
use App\Service\Config\Manager;
15
use Doctrine\Common\EventSubscriber;
16
use Doctrine\ORM\Event\LifecycleEventArgs;
17
use Doctrine\ORM\Events;
18
19
class DKIMDomainSubscriber implements EventSubscriber
20
{
21
    private $manager;
22
23
    public function __construct(Manager $manager)
24
    {
25
        $this->manager = $manager;
26
    }
27
28
    public function getSubscribedEvents(): array
29
    {
30
        return [
31
            Events::postUpdate,
32
            Events::postPersist,
33
            Events::postRemove,
34
        ];
35
    }
36
37
    public function postUpdate(LifecycleEventArgs $args): void
38
    {
39
        $this->doUpdate($args);
40
    }
41
42
    public function postPersist(LifecycleEventArgs $args): void
43
    {
44
        $this->doUpdate($args);
45
    }
46
47
    public function postRemove(LifecycleEventArgs $args): void
48
    {
49
        $this->doUpdate($args);
50
    }
51
52
    private function doUpdate(LifecycleEventArgs $args): void
53
    {
54
        $entity = $args->getObject();
55
56
        if ($entity instanceof Domain) {
57
            $this->manager->refresh();
58
        }
59
    }
60
}
61