Completed
Pull Request — master (#1)
by Rafał
03:36 queued 01:22
created

ConfigurePrefixCandidatesCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 21 4
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\Reference;
19
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
20
21
/**
22
 * Configures Symfony CMF PrefixCandidates service by adding
23
 * custom configurator which sets tenant aware base paths.
24
 */
25
class ConfigurePrefixCandidatesCompilerPass 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('cmf_routing.phpcr_candidates_prefix')
45
            ->setConfigurator([
46
                new Reference('swp_multi_tenancy.candidates_configurator'),
47
                'configure',
48
            ])
49
        ;
50
    }
51
}
52