@@ -24,43 +24,43 @@ |
||
24 | 24 | use SWP\Component\MultiTenancy\Model\TenantInterface; |
25 | 25 | |
26 | 26 | class CachedTenantContext extends TenantContext implements CachedTenantContextInterface { |
27 | - private $resolvedTenants = []; |
|
27 | + private $resolvedTenants = []; |
|
28 | 28 | |
29 | - public function getTenant(): ?TenantInterface { |
|
29 | + public function getTenant(): ?TenantInterface { |
|
30 | 30 | $currentRequest = $this->requestStack->getCurrentRequest(); |
31 | 31 | if ($currentRequest && $this->requestStack->getCurrentRequest()->attributes->get('exception') instanceof TenantNotFoundException) { |
32 | - return null; |
|
32 | + return null; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | if ($currentRequest === null) { |
36 | - return $this->tenant; |
|
36 | + return $this->tenant; |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | $cacheKey = self::getCacheKey($currentRequest->getHost()); |
40 | 40 | if (!array_key_exists($cacheKey, $this->resolvedTenants) || $this->resolvedTenants[$cacheKey] instanceof TenantInterface) { |
41 | - $this->resolvedTenants[$cacheKey] = parent::getTenant(); |
|
41 | + $this->resolvedTenants[$cacheKey] = parent::getTenant(); |
|
42 | 42 | } else { |
43 | - $this->tenant = $this->resolvedTenants[$cacheKey]; |
|
43 | + $this->tenant = $this->resolvedTenants[$cacheKey]; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | return $this->tenant; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - public function setTenant(TenantInterface $tenant): void { |
|
49 | + public function setTenant(TenantInterface $tenant): void { |
|
50 | 50 | parent::setTenant($tenant); |
51 | 51 | $this->dispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_ENABLE); |
52 | 52 | |
53 | 53 | $this->resolvedTenants[self::getCacheKey( |
54 | 54 | $tenant->getSubdomain() ? $tenant->getSubdomain() . '.' . $tenant->getDomainName() : $tenant->getDomainName() |
55 | 55 | )] = $tenant; |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | - public function reset(): void { |
|
58 | + public function reset(): void { |
|
59 | 59 | $this->tenant = null; |
60 | 60 | $this->resolvedTenants = []; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - private static function getCacheKey(string $host): string { |
|
63 | + private static function getCacheKey(string $host): string { |
|
64 | 64 | return md5('tenant_cache__' . $host); |
65 | - } |
|
65 | + } |
|
66 | 66 | } |
@@ -28,62 +28,62 @@ |
||
28 | 28 | * Class TenantContext. |
29 | 29 | */ |
30 | 30 | class TenantContext implements TenantContextInterface { |
31 | - /** |
|
32 | - * @var TenantInterface |
|
33 | - */ |
|
34 | - protected $tenant; |
|
31 | + /** |
|
32 | + * @var TenantInterface |
|
33 | + */ |
|
34 | + protected $tenant; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var TenantResolverInterface |
|
38 | - */ |
|
39 | - protected $tenantResolver; |
|
36 | + /** |
|
37 | + * @var TenantResolverInterface |
|
38 | + */ |
|
39 | + protected $tenantResolver; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var RequestStack |
|
43 | - */ |
|
44 | - protected $requestStack; |
|
41 | + /** |
|
42 | + * @var RequestStack |
|
43 | + */ |
|
44 | + protected $requestStack; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var EventDispatcherInterface |
|
48 | - */ |
|
49 | - protected $dispatcher; |
|
46 | + /** |
|
47 | + * @var EventDispatcherInterface |
|
48 | + */ |
|
49 | + protected $dispatcher; |
|
50 | 50 | |
51 | - /** |
|
52 | - * TenantContext constructor. |
|
53 | - */ |
|
54 | - public function __construct(TenantResolverInterface $tenantResolver, RequestStack $requestStack, |
|
55 | - EventDispatcherInterface $dispatcher) { |
|
51 | + /** |
|
52 | + * TenantContext constructor. |
|
53 | + */ |
|
54 | + public function __construct(TenantResolverInterface $tenantResolver, RequestStack $requestStack, |
|
55 | + EventDispatcherInterface $dispatcher) { |
|
56 | 56 | $this->tenantResolver = $tenantResolver; |
57 | 57 | $this->requestStack = $requestStack; |
58 | 58 | $this->dispatcher = $dispatcher; |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * {@inheritdoc} |
|
63 | - */ |
|
64 | - public function getTenant() { |
|
61 | + /** |
|
62 | + * {@inheritdoc} |
|
63 | + */ |
|
64 | + public function getTenant() { |
|
65 | 65 | if ($this->tenant !== null) |
66 | - return $this->tenant; |
|
66 | + return $this->tenant; |
|
67 | 67 | |
68 | 68 | $currentRequest = $this->requestStack->getCurrentRequest(); |
69 | 69 | if (null !== $currentRequest && false !== strpos($currentRequest->getRequestUri(), '_profiler')) { |
70 | - $profilerTenant = new Tenant(); |
|
71 | - $profilerTenant->setDomainName($currentRequest->getHost()); |
|
72 | - $this->setTenant($profilerTenant); |
|
73 | - return $profilerTenant; |
|
70 | + $profilerTenant = new Tenant(); |
|
71 | + $profilerTenant->setDomainName($currentRequest->getHost()); |
|
72 | + $this->setTenant($profilerTenant); |
|
73 | + return $profilerTenant; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | $newTenant = $this->tenantResolver->resolve($currentRequest ? $currentRequest->getHost() : null); |
77 | 77 | $this->setTenant($newTenant); |
78 | 78 | return $newTenant; |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * {@inheritdoc} |
|
83 | - */ |
|
84 | - public function setTenant(TenantInterface $tenant) { |
|
81 | + /** |
|
82 | + * {@inheritdoc} |
|
83 | + */ |
|
84 | + public function setTenant(TenantInterface $tenant) { |
|
85 | 85 | $this->tenant = $tenant; |
86 | 86 | |
87 | 87 | $this->dispatcher->dispatch(new GenericEvent($tenant), MultiTenancyEvents::TENANT_SET); |
88 | - } |
|
88 | + } |
|
89 | 89 | } |