8000 bug #29582 [DI] move RegisterServiceSubscribersPass before DecoratorS… · symfony/symfony@7028f84 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7028f84

Browse files
bug #29582 [DI] move RegisterServiceSubscribersPass before DecoratorServicePass (kbond)
This PR was merged into the 3.4 branch. Discussion ---------- [DI] move RegisterServiceSubscribersPass before DecoratorServicePass | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no| Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #29550 | License | MIT | Doc PR | n/a From #29550 (comment): The fact that `RegisterServiceSubscribersPass` runs after `DecoratorServicePass` makes it impossible to decorate a service implementing `ServiceSubscriberInterface` if the decorator does not implement it. Commits ------- c3271d9 [DI] move RegisterServiceSubscribersPass before DecoratorServicePass
2 parents 153220a + c3271d9 commit 7028f84

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public function __construct()
5151
$this->optimizationPasses = array(array(
5252
new ResolveChildDefinitionsPass(),
5353
new ServiceLocatorTagPass(),
54+
new RegisterServiceSubscribersPass(),
5455
new DecoratorServicePass(),
5556
new ResolveParameterPlaceHoldersPass(false),
5657
new ResolveFactoryClassPass(),
5758
new FactoryReturnTypePass($resolveClassPass),
5859
new CheckDefinitionValidityPass(),
59-
new RegisterServiceSubscribersPass(),
6060
new ResolveNamedArgumentsPass(),
6161
new AutowireRequiredMethodsPass(),
6262
new ResolveBindingsPass(),

src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
1818
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1919
use Symfony\Component\DependencyInjection\Reference;
20+
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
2021

2122
/**
2223
* This class tests the integration of the different compiler passes.
@@ -117,6 +118,21 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe
117118
$this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.');
118119
}
119120

121+
public function testCanDecorateServiceSubscriber()
122+
{
123+
$container = new ContainerBuilder();
124+
$container->register(ServiceSubscriberStub::class)
125+
->addTag('container.service_subscriber')
126+
->setPublic(true);
127+
128+
$container->register(DecoratedServiceSubscriber::class)
129+
->setDecoratedService(ServiceSubscriberStub::class);
130+
131+
$container->compile();
132+
133+
$this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class));
134+
}
135+
120136
/**
121137
* @dataProvider getYamlCompileTests
122138
*/
@@ -207,6 +223,18 @@ public function getYamlCompileTests()
207223
}
208224
}
209225

226+
class ServiceSubscriberStub implements ServiceSubscriberInterface
227+
{
228+
public static function getSubscribedServices()
229+
{
230+
return array();
231+
}
232+
}
233+
234+
class DecoratedServiceSubscriber
235+
{
236+
}
237+
210238
class IntegrationTestStub extends IntegrationTestStubParent
211239
{
212240
}

0 commit comments

Comments
 (0)
0