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
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
24
|
|
|
{ |
25
|
|
|
$configuration = new Configuration(); |
26
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
27
|
|
|
|
28
|
|
|
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
29
|
|
|
$loader->load('action.xml'); |
30
|
|
|
$loader->load('services.xml'); |
31
|
|
|
$loader->load('sitemap.xml'); |
32
|
|
|
|
33
|
|
|
$this->configureCache($container, $config); |
34
|
|
|
$this->configureStaticUrls($container, $config); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private function configureCache(ContainerBuilder $container, array $config): void |
38
|
|
|
{ |
39
|
|
|
if (null === $config['cache']['service']) { |
40
|
|
|
return; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$container->getDefinition(SitemapGenerator::class) |
44
|
|
|
->replaceArgument(2, new Reference($config['cache']['service'])) |
45
|
|
|
; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function configureStaticUrls(ContainerBuilder $container, array $config): void |
49
|
|
|
{ |
50
|
|
|
$container->setParameter('core23_sitemap.static_urls', $config['static']); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|