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
|
|
|
public function process(ContainerBuilder $container): void |
25
|
|
|
{ |
26
|
|
|
$serviceManager = $container->findDefinition(SitemapServiceManagerInterface::class); |
27
|
|
|
$definitionManager = $container->findDefinition(DefintionManagerInterface::class); |
28
|
|
|
|
29
|
|
|
foreach ($container->findTaggedServiceIds('core23.sitemap') as $id => $attributes) { |
30
|
|
|
$definition = $container->getDefinition($id); |
31
|
|
|
$definition->setPublic(true); |
32
|
|
|
|
33
|
|
|
$serviceManager->addMethodCall('addSitemap', [ |
34
|
|
|
$id, |
35
|
|
|
new Reference($id), |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
$definitionManager->addMethodCall('addDefinition', [ |
39
|
|
|
$id, |
40
|
|
|
]); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$this->addStaticUrls($container, $definitionManager); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
private function addStaticUrls(ContainerBuilder $container, Definition $definitionManager): void |
47
|
|
|
{ |
48
|
|
|
foreach ($container->getParameter('core23_sitemap.static_urls') as $options) { |
49
|
|
|
$definitionManager->addMethodCall('addDefinition', [ |
50
|
|
|
StaticSitemapService::class, $options, |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|