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 2222 */
2323class TestServiceContainerWeakRefPass implements CompilerPassInterface
2424{
25+ private $ privateTagName ;
26+
27+ public function __construct (string $ privateTagName = 'container.private ' )
28+ {
29+ $ this ->privateTagName = $ privateTagName ;
30+ }
31+
2532 public function process (ContainerBuilder $ container )
2633 {
2734 if (!$ container ->hasDefinition ('test.private_services_locator ' )) {
@@ -33,7 +40,7 @@ public function process(ContainerBuilder $container)
3340 $ hasErrors = method_exists (Definition::class, 'hasErrors ' ) ? 'hasErrors ' : 'getErrors ' ;
3441
3542 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 ()) {
3744 $ privateServices [$ id ] = new Reference ($ id , ContainerBuilder::IGNORE_ON_UNINITIALIZED_REFERENCE );
3845 }
3946 }
Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ public function testProcess()
3636 ->setPublic (true )
3737 ->addArgument (new Reference ('Test\private_used_shared_service ' ))
3838 ->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 ' ])
3945 ;
4046
4147 $ container ->register ('Test\private_used_shared_service ' );
@@ -48,6 +54,7 @@ public function testProcess()
4854 $ expected = [
4955 'Test\private_used_shared_service ' => new ServiceClosureArgument (new Reference ('Test\private_used_shared_service ' )),
5056 '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 ' )),
5158 'Psr\Container\ContainerInterface ' => new ServiceClosureArgument (new Reference ('service_container ' )),
5259 'Symfony\Component\DependencyInjection\ContainerInterface ' => new ServiceClosureArgument (new Reference ('service_container ' )),
5360 ];
You can’t perform that action at this time.
0 commit comments