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

Core23SitemapExtension::configureStaticUrls()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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;
13
14
use Core23\SitemapBundle\Generator\SitemapGenerator;
15
use Symfony\Component\Config\FileLocator;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Loader;
18
use Symfony\Component\DependencyInjection\Reference;
19
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
20
21
final class Core23SitemapExtension extends Extension
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function load(array $configs, ContainerBuilder $container): void
27
    {
28
        $configuration = new Configuration();
29
        $config        = $this->processConfiguration($configuration, $configs);
30
31
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
32
        $loader->load('action.xml');
33
        $loader->load('services.xml');
34
        $loader->load('sitemap.xml');
35
36
        $this->configureCache($container, $config);
37
        $this->configureStaticUrls($container, $config);
38
    }
39
40
    /**
41
     * @param ContainerBuilder $container
42
     * @param array            $config
43
     */
44
    private function configureCache(ContainerBuilder $container, array $config): void
45
    {
46
        if (null === $config['cache']['service']) {
47
            return;
48
        }
49
50
        $container->getDefinition(SitemapGenerator::class)
51
            ->replaceArgument(2, new Reference($config['cache']['service']));
52
    }
53
54
    /**
55
     * @param ContainerBuilder $container
56
     * @param array            $config
57
     */
58
    private function configureStaticUrls(ContainerBuilder $container, array $config): void
59
    {
60
        $container->setParameter('core23_sitemap.static_urls', $config['static']);
61
    }
62
}
63