Code Duplication    Length = 26-30 lines in 2 locations

DependencyInjection/Compiler/ConfigurePrefixCandidatesCompilerPass.php 1 location

@@ 24-53 (lines=30) @@
21
/**
22
 * Configures Symfony CMF PrefixCandidates to make the prefixes tenant aware.
23
 */
24
class ConfigurePrefixCandidatesCompilerPass implements CompilerPassInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasParameter('cmf_routing.backend_type_phpcr')
32
            || !$container->hasParameter('swp_multi_tenancy.backend_type_phpcr')) {
33
            return;
34
        }
35
36
        $bundles = $container->getParameter('kernel.bundles');
37
        if (!isset($bundles['CmfRoutingBundle'])) {
38
            throw new RuntimeException(
39
                'You have enabled the PHPCR backend but the CmfRoutingBundle is not registered'
40
            );
41
        }
42
43
        $container->getDefinition('cmf_routing.phpcr_candidates_prefix')
44
            ->setClass($container->getParameter('swp_multi_tenancy.prefix_candidates.class'))
45
            ->addMethodCall('setPathBuilder', [
46
                new Reference('swp_multi_tenancy.path_builder'),
47
            ])
48
            ->addMethodCall('setRoutePathsNames', [
49
                $container->getParameter('swp_multi_tenancy.persistence.phpcr.route_basepaths'),
50
            ])
51
        ;
52
    }
53
}
54

DependencyInjection/Compiler/TenantAwareRouterCompilerPass.php 1 location

@@ 25-50 (lines=26) @@
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