Skip to content

Commit 5889003

Browse files
[DI] Add "container.hot_path" tag to flag the hot path and inline related services
1 parent 19f15d7 commit 5889003

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class UnusedTagsPass implements CompilerPassInterface
2424
private $whitelist = array(
2525
'cache.pool.clearer',
2626
'console.command',
27+
'container.hot_path',
2728
'container.service_locator',
2829
'container.service_subscriber',
2930
'controller.service_arguments',

FrameworkBundle.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
use Symfony\Component\Form\DependencyInjection\FormPass;
4444
use Symfony\Component\HttpFoundation\Request;
4545
use Symfony\Component\HttpKernel\Bundle\Bundle;
46+
use Symfony\Component\HttpKernel\KernelEvents;
4647
use Symfony\Component\Config\Resource\ClassExistenceResource;
4748
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass;
4849
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
@@ -83,14 +84,22 @@ public function build(ContainerBuilder $container)
8384
{
8485
parent::build($container);
8586

87+
$hotPathEvents = array(
88+
KernelEvents::REQUEST,
89+
KernelEvents::CONTROLLER,
90+
KernelEvents::CONTROLLER_ARGUMENTS,
91+
KernelEvents::RESPONSE,
92+
KernelEvents::FINISH_REQUEST,
93+
);
94+
8695
$container->addCompilerPass(new LoggerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
8796
$container->addCompilerPass(new RegisterControllerArgumentLocatorsPass());
8897
$container->addCompilerPass(new RemoveEmptyControllerArgumentLocatorsPass(), PassConfig::TYPE_BEFORE_REMOVING);
8998
$container->addCompilerPass(new RoutingResolverPass());
9099
$container->addCompilerPass(new ProfilerPass());
91100
// must be registered before removing private services as some might be listeners/subscribers
92101
// but as late as possible to get resolved parameters
93-
$container->addCompilerPass(new RegisterListenersPass(), PassConfig::TYPE_BEFORE_REMOVING);
102+
$container->addCompilerPass((new RegisterListenersPass())->setHotPathEvents($hotPathEvents), PassConfig::TYPE_BEFORE_REMOVING);
94103
$container->addCompilerPass(new TemplatingPass());
95104
$this->addCompilerPassIfExists($container, AddConstraintValidatorsPass::class, PassConfig::TYPE_BEFORE_REMOVING);
96105
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);

Resources/config/services.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher" public="true">
1111
<argument type="service" id="service_container" />
12+
<tag name="container.hot_path" />
1213
</service>
1314
<service id="Symfony\Component\EventDispatcher\EventDispatcherInterface" alias="event_dispatcher" />
1415

@@ -17,6 +18,7 @@
1718
<argument type="service" id="controller_resolver" />
1819
<argument type="service" id="request_stack" />
1920
<argument type="service" id="argument_resolver" />
21+
<tag name="container.hot_path" />
2022
</service>
2123
<service id="Symfony\Component\HttpKernel\HttpKernelInterface" alias="http_kernel" />
2224

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/class-loader": "~3.2",
2323
"symfony/dependency-injection": "~3.4|~4.0",
2424
"symfony/config": "~3.4|~4.0",
25-
"symfony/event-dispatcher": "^3.3.1|~4.0",
25+
"symfony/event-dispatcher": "^3.4-beta4|~4.0-beta4",
2626
"symfony/http-foundation": "^3.3.11|~4.0",
2727
"symfony/http-kernel": "~3.4|~4.0",
2828
"symfony/polyfill-mbstring": "~1.0",

0 commit comments

Comments
 (0)