|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright 2016 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 2016 Sourcefabric z.ú. |
|
12
|
|
|
* @license http://www.superdesk.org/license |
|
13
|
|
|
*/ |
|
14
|
|
|
namespace SWP\MultiTenancyBundle\DependencyInjection\Compiler; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
18
|
|
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Tenant aware Router compiler pass. Configures and registers TenantAwareRouter |
|
23
|
|
|
* in Symfony CMF routing under the 'routers_by_id' keys in config. |
|
24
|
|
|
*/ |
|
25
|
|
|
class TenantAwareRouterCompilerPass implements CompilerPassInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* {@inheritdoc} |
|
29
|
|
|
*/ |
|
30
|
|
|
public function process(ContainerBuilder $container) |
|
31
|
|
|
{ |
|
32
|
|
|
if (!$container->hasParameter('cmf_routing.backend_type_phpcr') |
|
33
|
|
|
|| !$container->hasParameter('swp_multi_tenancy.backend_type_phpcr')) { |
|
34
|
|
|
return; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
|
38
|
|
|
if (!isset($bundles['CmfRoutingBundle'])) { |
|
39
|
|
|
throw new RuntimeException( |
|
40
|
|
|
'You have enabled the PHPCR backend but the CmfRoutingBundle is not registered' |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$container->getDefinition('swp_multi_tenancy.tenant_aware_router') |
|
45
|
|
|
->setArguments($container->getDefinition('cmf_routing.dynamic_router')->getArguments()) |
|
46
|
|
|
->setMethodCalls($container->getDefinition('cmf_routing.dynamic_router')->getMethodCalls()) |
|
47
|
|
|
->addMethodCall('setPathBuilder', [new Reference('swp_multi_tenancy.path_builder')]) |
|
48
|
|
|
; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|