Passed
Push — di ( 61d74f...f00c6d )
by Arnaud
15:03 queued 11:43
created

TwigExtensionPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <[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
declare(strict_types=1);
13
14
namespace Cecil\DependencyInjection\CompilerPass;
15
16
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
/**
21
 * Compiler pass for automatic registration of Twig extensions.
22
 *
23
 * This compiler pass finds all services tagged with 'cecil.twig.extension'
24
 * and registers them with the Twig renderer service.
25
 */
26
class TwigExtensionPass implements CompilerPassInterface
27
{
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function process(ContainerBuilder $container): void
32
    {
33
        // Si le Renderer Twig n'existe pas, on ne fait rien
34
        if (!$container->has('Cecil\Renderer\Twig')) {
35
            return;
36
        }
37
38
        $definition = $container->findDefinition('Cecil\Renderer\Twig');
39
        $taggedServices = $container->findTaggedServiceIds('cecil.twig.extension');
40
41
        // Enregistrement des extensions Twig
42
        foreach ($taggedServices as $id => $tags) {
43
            $definition->addMethodCall('addExtension', [
44
                new Reference($id)
45
            ]);
46
        }
47
    }
48
}
49