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
|
|
|
|
15
|
|
|
namespace SWP\Bundle\MultiTenancyBundle\DependencyInjection\Compiler; |
16
|
|
|
|
17
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException; |
20
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Tenant aware Router compiler pass. Configures and registers TenantAwareRouter |
24
|
|
|
* in Symfony CMF routing under the 'routers_by_id' keys in config. |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
class TenantAwareRouterCompilerPass implements CompilerPassInterface |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function process(ContainerBuilder $container) |
32
|
|
|
{ |
33
|
|
|
if (!$container->hasParameter('cmf_routing.backend_type_phpcr') |
34
|
|
|
|| !$container->hasParameter('swp_multi_tenancy.backend_type_phpcr')) { |
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
39
|
|
|
if (!isset($bundles['CmfRoutingBundle'])) { |
40
|
|
|
throw new RuntimeException( |
41
|
|
|
'You have enabled the PHPCR backend but the CmfRoutingBundle is not registered' |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$container->getDefinition('swp_multi_tenancy.tenant_aware_router') |
46
|
|
|
->setArguments($container->getDefinition('cmf_routing.dynamic_router')->getArguments()) |
47
|
|
|
->setMethodCalls($container->getDefinition('cmf_routing.dynamic_router')->getMethodCalls()) |
48
|
|
|
->addMethodCall('setPathBuilder', [new Reference('swp_multi_tenancy.path_builder')]); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.