Completed
Push — master ( 3ef484...ea5778 )
by Paweł
08:46
created

ProcessOrganizationRulesSubscriber::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\EventSubscriber;
18
19
use SWP\Bundle\MultiTenancyBundle\MultiTenancyEvents;
20
use SWP\Component\Bridge\Events;
21
use SWP\Component\Rule\Processor\RuleProcessorInterface;
22
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
23
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
24
use Symfony\Component\EventDispatcher\GenericEvent;
25
26
class ProcessOrganizationRulesSubscriber implements EventSubscriberInterface
27
{
28
    /**
29
     * @var RuleProcessorInterface
30
     */
31
    private $ruleProcessor;
32
33
    /**
34
     * @var EventDispatcherInterface
35
     */
36
    private $eventDispatcher;
37
38
    /**
39
     * ProcessArticleRulesSubscriber constructor.
40
     *
41
     * @param RuleProcessorInterface   $ruleProcessor
42
     * @param EventDispatcherInterface $eventDispatcher
43
     */
44
    public function __construct(
45
        RuleProcessorInterface $ruleProcessor,
46
        EventDispatcherInterface $eventDispatcher
47
    ) {
48
        $this->ruleProcessor = $ruleProcessor;
49
        $this->eventDispatcher = $eventDispatcher;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public static function getSubscribedEvents()
56
    {
57
        return [
58
            Events::PACKAGE_POST_CREATE => 'processRules',
59
            Events::PACKAGE_POST_UPDATE => 'processRules',
60
        ];
61
    }
62
63
    /**
64
     * @param GenericEvent $event
65
     */
66
    public function processRules(GenericEvent $event)
67
    {
68
        $this->eventDispatcher->dispatch(MultiTenancyEvents::TENANTABLE_DISABLE);
69
        $this->ruleProcessor->process($event->getSubject());
70
        $this->eventDispatcher->dispatch(MultiTenancyEvents::TENANTABLE_ENABLE);
71
    }
72
}
73