Completed
Push — master ( 9c95f5...e428dc )
by Paweł
06:06
created

ScopeContextSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Core Bundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\CoreBundle\EventSubscriber;
16
17
use SWP\Bundle\MultiTenancyBundle\MultiTenancyEvents;
18
use SWP\Bundle\CoreBundle\Context\ScopeContextInterface;
19
use SWP\Bundle\SettingsBundle\Model\SettingsOwnerInterface;
20
use SWP\Component\MultiTenancy\Model\TenantInterface;
21
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
22
use Symfony\Component\EventDispatcher\GenericEvent;
23
24
class ScopeContextSubscriber implements EventSubscriberInterface
25
{
26
    /**
27
     * @var ScopeContextInterface
28
     */
29
    protected $scopeContext;
30
31
    /**
32
     * ScopeContextSubscriber constructor.
33
     *
34
     * @param ScopeContextInterface $scopeContext
35
     */
36
    public function __construct(ScopeContextInterface $scopeContext)
37
    {
38
        $this->scopeContext = $scopeContext;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public static function getSubscribedEvents()
45
    {
46
        return [
47
            MultiTenancyEvents::TENANT_SET => 'onTenantSet',
48
        ];
49
    }
50
51
    /**
52
     * @param GenericEvent $event
53
     */
54
    public function onTenantSet(GenericEvent $event)
55
    {
56
        $tenant = $event->getSubject();
57
58
        if ($tenant instanceof TenantInterface && $tenant instanceof SettingsOwnerInterface) {
59
            $this->scopeContext->setScopeOwner(ScopeContextInterface::SCOPE_TENANT, $tenant);
60
            $this->scopeContext->setScopeOwner(ScopeContextInterface::SCOPE_ORGANIZATION, $tenant->getOrganization());
61
        }
62
    }
63
}
64