Skip to content

Commit

Permalink
bug #29582 [DI] move RegisterServiceSubscribersPass before DecoratorS…
Browse files Browse the repository at this point in the history
…ervicePass (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
  • Loading branch information
nicolas-grekas committed Dec 12, 2018
2 parents 153220a + c3271d9 commit 7028f84
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -51,12 +51,12 @@ public function __construct()
$this->optimizationPasses = array(array(
new ResolveChildDefinitionsPass(),
new ServiceLocatorTagPass(),
new RegisterServiceSubscribersPass(),
new DecoratorServicePass(),
new ResolveParameterPlaceHoldersPass(false),
new ResolveFactoryClassPass(),
new FactoryReturnTypePass($resolveClassPass),
new CheckDefinitionValidityPass(),
new RegisterServiceSubscribersPass(),
new ResolveNamedArgumentsPass(),
new AutowireRequiredMethodsPass(),
new ResolveBindingsPass(),
Expand Down
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;

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

public function testCanDecorateServiceSubscriber()
{
$container = new ContainerBuilder();
$container->register(ServiceSubscriberStub::class)
->addTag('container.service_subscriber')
->setPublic(true);

$container->register(DecoratedServiceSubscriber::class)
->setDecoratedService(ServiceSubscriberStub::class);

$container->compile();

$this->assertInstanceOf(DecoratedServiceSubscriber::class, $container->get(ServiceSubscriberStub::class));
}

/**
* @dataProvider getYamlCompileTests
*/
Expand Down Expand Up @@ -207,6 +223,18 @@ public function getYamlCompileTests()
}
}

class ServiceSubscriberStub implements ServiceSubscriberInterface
{
public static function getSubscribedServices()
{
return array();
}
}

class DecoratedServiceSubscriber
{
}

class IntegrationTestStub extends IntegrationTestStubParent
{
}
Expand Down

0 comments on commit 7028f84

Please sign in to comment.