|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Component. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2015 Sourcefabric z.u. 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 2015 Sourcefabric z.ú. |
|
12
|
|
|
* @license http://www.superdesk.org/license |
|
13
|
|
|
*/ |
|
14
|
|
|
namespace SWP\MultiTenancyBundle\Context; |
|
15
|
|
|
|
|
16
|
|
|
use SWP\Component\MultiTenancy\Context\TenantContextInterface; |
|
17
|
|
|
use SWP\Component\MultiTenancy\Model\Tenant; |
|
18
|
|
|
use SWP\Component\MultiTenancy\Model\TenantInterface; |
|
19
|
|
|
use SWP\Component\MultiTenancy\Resolver\TenantResolverInterface; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class TenantContext. |
|
24
|
|
|
*/ |
|
25
|
|
|
class TenantContext implements TenantContextInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var TenantInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $tenant; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var TenantResolverInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $tenantResolver; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var RequestStack |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $requestStack; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* TenantContext constructor. |
|
44
|
|
|
* |
|
45
|
|
|
* @param TenantResolverInterface $tenantResolver |
|
46
|
|
|
* @param RequestStack $requestStack |
|
47
|
|
|
*/ |
|
48
|
|
|
public function __construct(TenantResolverInterface $tenantResolver, RequestStack $requestStack) |
|
49
|
|
|
{ |
|
50
|
|
|
$this->tenantResolver = $tenantResolver; |
|
51
|
|
|
$this->requestStack = $requestStack; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritdoc} |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getTenant() |
|
58
|
|
|
{ |
|
59
|
|
|
if (null === $this->tenant) { |
|
60
|
|
|
$currentRequest = $this->requestStack->getCurrentRequest(); |
|
61
|
|
|
$this->tenant = $this->tenantResolver->resolve( |
|
62
|
|
|
$currentRequest ? $currentRequest->getHost() : null |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $this->tenant; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setTenant(TenantInterface $tenant) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->tenant = $tenant; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|