File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
DependencyInjection/Compiler
Tests/DependencyInjection/Compiler Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 22
22
*/
23
23
class TestServiceContainerWeakRefPass implements CompilerPassInterface
24
24
{
25
+ private $ privateTagName ;
26
+
27
+ public function __construct (string $ privateTagName = 'container.private ' )
28
+ {
29
+ $ this ->privateTagName = $ privateTagName ;
30
+ }
31
+
25
32
public function process (ContainerBuilder $ container )
26
33
{
27
34
if (!$ container ->hasDefinition ('test.private_services_locator ' )) {
@@ -33,7 +40,7 @@ public function process(ContainerBuilder $container)
33
40
$ hasErrors = method_exists (Definition::class, 'hasErrors ' ) ? 'hasErrors ' : 'getErrors ' ;
34
41
35
42
foreach ($ definitions as $ id => $ definition ) {
36
- if ($ id && '. ' !== $ id [0 ] && (!$ definition ->isPublic () || $ definition ->isPrivate ()) && !$ definition ->$ hasErrors () && !$ definition ->isAbstract ()) {
43
+ if ($ id && '. ' !== $ id [0 ] && (!$ definition ->isPublic () || $ definition ->isPrivate () || $ definition -> hasTag ( $ this -> privateTagName ) ) && !$ definition ->$ hasErrors () && !$ definition ->isAbstract ()) {
37
44
$ privateServices [$ id ] = new Reference ($ id , ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE );
38
45
}
39
46
}
Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ public function testProcess()
36
36
->setPublic (true )
37
37
->addArgument (new Reference ('Test\private_used_shared_service ' ))
38
38
->addArgument (new Reference ('Test\private_used_non_shared_service ' ))
39
+ ->addArgument (new Reference ('Test\soon_private_service ' ))
40
+ ;
41
+
42
+ $ container ->register ('Test\soon_private_service ' )
43
+ ->setPublic (true )
44
+ ->addTag ('container.private ' , ['package ' => 'foo/bar ' , 'version ' => '1.42 ' ])
39
45
;
40
46
41
47
$ container ->register ('Test\private_used_shared_service ' );
@@ -48,6 +54,7 @@ public function testProcess()
48
54
$ expected = [
49
55
'Test\private_used_shared_service ' => new ServiceClosureArgument (new Reference ('Test\private_used_shared_service ' )),
50
56
'Test\private_used_non_shared_service ' => new ServiceClosureArgument (new Reference ('Test\private_used_non_shared_service ' )),
57
+ 'Test\soon_private_service ' => new ServiceClosureArgument (new Reference ('.container.private.Test\soon_private_service ' )),
51
58
'Psr\Container\ContainerInterface ' => new ServiceClosureArgument (new Reference ('service_container ' )),
52
59
'Symfony\Component\DependencyInjection\ContainerInterface ' => new ServiceClosureArgument (new Reference ('service_container ' )),
53
60
];
You can’t perform that action at this time.
0 commit comments