Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
convert_events
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
3.58
0.00% covered (danger)
0.00%
0 / 1
 process
60.00% covered (warning)
60.00%
3 / 5
0.00% covered (danger)
0.00%
0 / 1
3.58
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\di\pass;
15
16use Symfony\Component\DependencyInjection\ContainerBuilder;
17use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
19/**
20 * Converts event types to Symfony ones
21 */
22class convert_events implements CompilerPassInterface
23{
24    /** @var string[] Map for conversions of types */
25    private static array $conversions = [
26        'event.listener_listener'    => 'kernel.event_listener',
27        'event.listener'            => 'kernel.event_subscriber',
28    ];
29
30    /**
31     * Modify the container before it is passed to the rest of the code
32     * Add Symfony event tags to previously used phpBB ones
33     *
34     * @param ContainerBuilder $container ContainerBuilder object
35     * @return void
36     */
37    public function process(ContainerBuilder $container): void
38    {
39        // Add alias for event dispatcher
40        $container->addAliases(['dispatcher' => 'event_dispatcher']);
41
42        foreach (self::$conversions as $from => $to)
43        {
44            foreach ($container->findTaggedServiceIds($from, true) as $id => $tags)
45            {
46                $definition = $container->getDefinition($id);
47                $definition->addTag($to);
48            }
49        }
50    }
51}