Code Duplication    Length = 26-30 lines in 2 locations

DependencyInjection/Compiler/ConfigurePrefixCandidatesCompilerPass.php 1 location

@@ 25-54 (lines=30) @@
22
/**
23
 * Configures Symfony CMF PrefixCandidates to make the prefixes tenant aware.
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
            ->setClass($container->getParameter('swp_multi_tenancy.prefix_candidates.class'))
46
            ->addMethodCall('setPathBuilder', [
47
                new Reference('swp_multi_tenancy.path_builder'),
48
            ])
49
            ->addMethodCall('setRoutePathsNames', [
50
                $container->getParameter('swp_multi_tenancy.persistence.phpcr.route_basepaths'),
51
            ]);
52
    }
53
}
54

DependencyInjection/Compiler/TenantAwareRouterCompilerPass.php 1 location

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