Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
markpublic_pass
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
8.70
0.00% covered (danger)
0.00%
0 / 1
 process
77.78% covered (warning)
77.78%
7 / 9
0.00% covered (danger)
0.00%
0 / 1
8.70
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* Marks all services public
21*/
22class markpublic_pass implements CompilerPassInterface
23{
24    /**
25    * Modify the container before it is passed to the rest of the code
26    * Mark services as public by default unless they were explicitly marked as private
27    *
28    * @param ContainerBuilder $container ContainerBuilder object
29    * @return void
30    */
31    public function process(ContainerBuilder $container)
32    {
33        $service_definitions = $container->getDefinitions();
34        foreach ($service_definitions as $definition)
35        {
36            $changes = $definition->getChanges();
37
38            /* Check if service definition contains explicit 'public' key (changed default state)
39             * If it does and the service is private, then service was explicitly marked as private
40             * Don't mark it as public then
41             */
42            $definition_override_public = isset($changes['public']) && $changes['public'];
43            if (!$definition_override_public && $definition->isPrivate())
44            {
45                $definition->setPublic(true);
46            }
47        }
48
49        foreach ($container->getAliases() as $alias)
50        {
51            // Only mark alias as public if original service is public too
52            if ($service_definitions[(string) $alias]->isPublic() && $alias->isPrivate())
53            {
54                $alias->setPublic(true);
55            }
56        }
57    }
58}