Skip to content

Commit e4b9ea9

Browse files
Allow fetching private services from ServiceLocator
1 parent 8ae41d1 commit e4b9ea9

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Diff for: src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public function processNode(Node $node, Scope $scope): array
5454
$isTestContainerType = (new ObjectType('Symfony\Bundle\FrameworkBundle\Test\TestContainer'))->isSuperTypeOf($argType);
5555
$isOldServiceSubscriber = (new ObjectType('Symfony\Component\DependencyInjection\ServiceSubscriberInterface'))->isSuperTypeOf($argType);
5656
$isServiceSubscriber = (new ObjectType('Symfony\Contracts\Service\ServiceSubscriberInterface'))->isSuperTypeOf($argType);
57-
if ($isTestContainerType->yes() || $isOldServiceSubscriber->yes() || $isServiceSubscriber->yes()) {
57+
$isServiceLocator = (new ObjectType('Symfony\Component\DependencyInjection\ServiceLocator'))->isSuperTypeOf($argType);
58+
if ($isTestContainerType->yes() || $isOldServiceSubscriber->yes() || $isServiceSubscriber->yes() || $isServiceLocator->yes()) {
5859
return [];
5960
}
6061

Diff for: tests/Rules/Symfony/ExampleController.php

+5
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,9 @@ public function unknownGuardedServiceOutsideOfContext(): void
3939
$this->get('unknown');
4040
}
4141

42+
public function privateServiceFromServiceLocator(): void
43+
{
44+
$this->get('service_locator')->get('private');
45+
}
46+
4247
}

Diff for: tests/Rules/Symfony/container.xml

+5
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
<services>
44
<service id="private" class="Foo" public="false"></service>
55
<service id="public" class="Foo"></service>
6+
<service id="service_locator" class="Symfony\Component\DependencyInjection\ServiceLocator" public="true">
7+
<argument type="collection">
8+
<argument key="private" type="service" id="private"/>
9+
</argument>
10+
</service>
611
</services>
712
</container>

0 commit comments

Comments
 (0)