Completed
Push — symfony4 ( c6a911...b0a2f3 )
by
unknown
37:19
created

SetAllServicesPublicPass   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 17
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 32 17
1
<?php
2
3
/**
4
 * File containing the FieldTypeCollectionPass class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\Base\Container\Compiler;
10
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
14
/**
15
 * This Pass overrides all services to be public.
16
 *
17
 * It is a workaround to the change in Symfony 4 which makes all services private by default.
18
 * Our integration tests are not prepared for this as they get services directly from the Container.
19
 *
20
 * WARNING! DO NOT USE IT IN YOUR APPLICATION.
21
 *
22
 * Inspired by \Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass
23
 */
24
class SetAllServicesPublicPass implements CompilerPassInterface
25
{
26
    /**
27
     * @param \Symfony\Component\DependencyInjection\ContainerBuilder $containerBuilder
28
     */
29
    public function process(ContainerBuilder $containerBuilder)
30
    {
31
        $definitions = $containerBuilder->getDefinitions();
32
        foreach ($definitions as $id => $definition) {
33
            if (
34
                $id && '.' !== $id[0]
35
                && (!$definition->isPublic() || $definition->isPrivate())
36
                && !$definition->getErrors()
37
                && !$definition->isAbstract()
38
            ) {
39
//                $definition->setPrivate(false);
40
//                $definition->setPublic(true);
41
            }
42
        }
43
44
        $aliases = $containerBuilder->getAliases();
45
        foreach ($aliases as $id => $alias) {
46
            if ($id && '.' !== $id[0] && (!$alias->isPublic() || $alias->isPrivate())) {
47
                while (isset($aliases[$target = (string) $alias])) {
48
                    $alias = $aliases[$target];
49
                }
50
                if (
51
                    isset($definitions[$target])
52
                    && !$definitions[$target]->getErrors()
53
                    && !$definitions[$target]->isAbstract()
54
                ) {
55
//                    $definition->setPrivate(false);
56
//                    $definition->setPublic(true);
57
                }
58
            }
59
        }
60
    }
61
}
62