Completed
Push — master ( b10e46...20af00 )
by Christian
263:11
created

SitemapCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 21 2
A addStaticUrls() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\SitemapBundle\DependencyInjection\Compiler;
13
14
use Core23\SitemapBundle\Definition\DefintionManagerInterface;
15
use Core23\SitemapBundle\Sitemap\SitemapServiceManagerInterface;
16
use Core23\SitemapBundle\Sitemap\StaticSitemapService;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Definition;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
final class SitemapCompilerPass implements CompilerPassInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function process(ContainerBuilder $container): void
28
    {
29
        $serviceManager    = $container->findDefinition(SitemapServiceManagerInterface::class);
30
        $definitionManager = $container->findDefinition(DefintionManagerInterface::class);
31
32
        foreach ($container->findTaggedServiceIds('core23.sitemap') as $id => $attributes) {
33
            $definition = $container->getDefinition($id);
34
            $definition->setPublic(true);
35
36
            $serviceManager->addMethodCall('addSitemap', [
37
                $id,
38
                new Reference($id),
39
            ]);
40
41
            $definitionManager->addMethodCall('addDefinition', [
42
                $id,
43
            ]);
44
        }
45
46
        $this->addStaticUrls($container, $definitionManager);
47
    }
48
49
    /**
50
     * @param ContainerBuilder $container
51
     * @param Definition       $definitionManager
52
     */
53
    private function addStaticUrls(ContainerBuilder $container, Definition $definitionManager): void
54
    {
55
        foreach ($container->getParameter('core23_sitemap.static_urls') as $options) {
56
            $definitionManager->addMethodCall('addDefinition', [
57
                StaticSitemapService::class, $options,
58
            ]);
59
        }
60
    }
61
}
62