|
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
|
|
|
|