|
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\Serializer; |
|
18
|
|
|
|
|
19
|
|
|
use JMS\Serializer\GraphNavigator; |
|
20
|
|
|
use JMS\Serializer\Handler\SubscribingHandlerInterface; |
|
21
|
|
|
use JMS\Serializer\JsonSerializationVisitor; |
|
22
|
|
|
use SWP\Bundle\CoreBundle\Model\TenantInterface; |
|
23
|
|
|
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface; |
|
24
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
25
|
|
|
|
|
26
|
|
|
final class TenantHandler implements SubscribingHandlerInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var TenantRepositoryInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $tenantRepository; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var RouterInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $router; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* TenantHandler constructor. |
|
40
|
|
|
* |
|
41
|
|
|
* @param TenantRepositoryInterface $tenantRepository |
|
42
|
|
|
* @param RouterInterface $router |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(TenantRepositoryInterface $tenantRepository, RouterInterface $router) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->tenantRepository = $tenantRepository; |
|
47
|
|
|
$this->router = $router; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritdoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public static function getSubscribingMethods() |
|
54
|
|
|
{ |
|
55
|
|
|
return array( |
|
56
|
|
|
array( |
|
57
|
|
|
'direction' => GraphNavigator::DIRECTION_SERIALIZATION, |
|
58
|
|
|
'format' => 'json', |
|
59
|
|
|
'type' => TenantInterface::class, |
|
60
|
|
|
'method' => 'serializeToJson', |
|
61
|
|
|
), |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function serializeToJson( |
|
66
|
|
|
JsonSerializationVisitor $visitor, |
|
|
|
|
|
|
67
|
|
|
string $tenantCode |
|
68
|
|
|
) { |
|
69
|
|
|
/** @var TenantInterface $tenant */ |
|
70
|
|
|
$tenant = $this->tenantRepository->findOneByCode($tenantCode); |
|
71
|
|
|
|
|
72
|
|
|
if (null === $tenant) { |
|
73
|
|
|
return; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return [ |
|
77
|
|
|
'id' => $tenant->getId(), |
|
78
|
|
|
'subdomain' => $tenant->getSubdomain(), |
|
79
|
|
|
'domainName' => $tenant->getDomainName(), |
|
80
|
|
|
'name' => $tenant->getName(), |
|
81
|
|
|
'ampEnabled' => $tenant->isAmpEnabled(), |
|
82
|
|
|
'_links' => [ |
|
83
|
|
|
'self' => [ |
|
84
|
|
|
'href' => $this->router->generate('swp_api_core_get_tenant', ['code' => $tenantCode]), |
|
85
|
|
|
], |
|
86
|
|
|
], |
|
87
|
|
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.