Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82543d0

Browse files
[DI] add tag "container.preload" tag to declare sidekick classes to preload
1 parent4dabd00 commit82543d0

File tree

12 files changed

+78
-20
lines changed

12 files changed

+78
-20
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class UnusedTagsPass implements CompilerPassInterface
3232
'container.env_var_loader',
3333
'container.env_var_processor',
3434
'container.hot_path',
35+
'container.preload',
3536
'container.reversible',
3637
'container.service_locator',
3738
'container.service_locator_context',

‎src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
<argumenttype="service"id="twig.runtime_loader" />
1919
</call>
2020
<configuratorservice="twig.configurator.environment"method="configure" />
21+
<tagname="container.preload"class="Twig\Cache\FilesystemCache" />
22+
<tagname="container.preload"class="Twig\Extension\CoreExtension" />
23+
<tagname="container.preload"class="Twig\Extension\EscaperExtension" />
24+
<tagname="container.preload"class="Twig\Extension\OptimizerExtension" />
25+
<tagname="container.preload"class="Twig\Extension\StagingExtension" />
26+
<tagname="container.preload"class="Twig\ExtensionSet" />
2127
</service>
2228
<serviceid="Twig_Environment"alias="twig" />
2329
<serviceid="Twig\Environment"alias="twig" />

‎src/Symfony/Bundle/TwigBundle/TwigBundle.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,6 @@
1919
useSymfony\Component\DependencyInjection\Compiler\PassConfig;
2020
useSymfony\Component\DependencyInjection\ContainerBuilder;
2121
useSymfony\Component\HttpKernel\Bundle\Bundle;
22-
useTwig\Cache\FilesystemCache;
23-
useTwig\Extension\CoreExtension;
24-
useTwig\Extension\EscaperExtension;
25-
useTwig\Extension\OptimizerExtension;
26-
useTwig\Extension\StagingExtension;
27-
useTwig\ExtensionSet;
28-
29-
// Help opcache.preload discover always-needed symbols
30-
class_exists(FilesystemCache::class);
31-
class_exists(CoreExtension::class);
32-
class_exists(EscaperExtension::class);
33-
class_exists(OptimizerExtension::class);
34-
class_exists(StagingExtension::class);
35-
class_exists(ExtensionSet::class);
3622

3723
/**
3824
* Bundle.

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* added support to autowire public typed properties in php 7.4
88
* added support for defining method calls, a configurator, and property setters in`InlineServiceConfigurator`
99
* added possibility to define abstract service arguments
10+
* added tag "container.preload" to declare sidekick classes to preload
1011

1112
5.0.0
1213
-----

‎src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class PhpDumper extends Dumper
7878
private$namespace;
7979
private$asFiles;
8080
private$hotPathTag;
81+
private$preloadTag;
8182
private$inlineFactories;
8283
private$inlineRequires;
8384
private$inlinedRequires = [];
@@ -143,6 +144,7 @@ public function dump(array $options = [])
143144
'as_files' =>false,
144145
'debug' =>true,
145146
'hot_path_tag' =>'container.hot_path',
147+
'preload_tag' =>'container.preload',
146148
'inline_factories_parameter' =>'container.dumper.inline_factories',
147149
'inline_class_loader_parameter' =>'container.dumper.inline_class_loader',
148150
'preload_classes' => [],
@@ -154,6 +156,7 @@ public function dump(array $options = [])
154156
$this->namespace =$options['namespace'];
155157
$this->asFiles =$options['as_files'];
156158
$this->hotPathTag =$options['hot_path_tag'];
159+
$this->preloadTag =$options['preload_tag'];
157160
$this->inlineFactories =$this->asFiles &&$options['inline_factories_parameter'] && (!$this->container->hasParameter($options['inline_factories_parameter']) ||$this->container->getParameter($options['inline_factories_parameter']));
158161
$this->inlineRequires =$options['inline_class_loader_parameter'] && ($this->container->hasParameter($options['inline_class_loader_parameter']) ?$this->container->getParameter($options['inline_class_loader_parameter']) : (\PHP_VERSION_ID <70400 ||$options['debug']));
159162
$this->serviceLocatorTag =$options['service_locator_tag'];
@@ -560,7 +563,7 @@ private function addServiceInclude(string $cId, Definition $definition): string
560563
$lineage = [];
561564
foreach ($this->inlinedDefinitionsas$def) {
562565
if (!$def->isDeprecated()) {
563-
foreach ($this->getClasses($def)as$class) {
566+
foreach ($this->getClasses($def,$cId)as$class) {
564567
$this->collectLineage($class,$lineage);
565568
}
566569
}
@@ -572,7 +575,7 @@ private function addServiceInclude(string $cId, Definition $definition): string
572575
&&$this->container->has($id)
573576
&&$this->isTrivialInstance($def =$this->container->findDefinition($id))
574577
) {
575-
foreach ($this->getClasses($def)as$class) {
578+
foreach ($this->getClasses($def,$cId)as$class) {
576579
$this->collectLineage($class,$lineage);
577580
}
578581
}
@@ -826,7 +829,7 @@ protected function {$methodName}($lazyInitialization)
826829
$code .=sprintf(" trigger_deprecation('', '', %s);\n\n",$this->export($definition->getDeprecationMessage($id)));
827830
}else {
828831
foreach ($this->inlinedDefinitionsas$def) {
829-
foreach ($this->getClasses($def)as$class) {
832+
foreach ($this->getClasses($def,$id)as$class) {
830833
$this->preload[$class] =$class;
831834
}
832835
}
@@ -991,7 +994,7 @@ private function addServices(array &$services = null): string
991994
}else {
992995
$services[$id] =null;
993996

994-
foreach ($this->getClasses($definition)as$class) {
997+
foreach ($this->getClasses($definition,$id)as$class) {
995998
$this->preload[$class] =$class;
996999
}
9971000
}
@@ -1376,7 +1379,7 @@ private function addInlineRequires(): string
13761379
$inlinedDefinitions =$this->getDefinitionsFromArguments([$definition]);
13771380

13781381
foreach ($inlinedDefinitionsas$def) {
1379-
foreach ($this->getClasses($def)as$class) {
1382+
foreach ($this->getClasses($def,$id)as$class) {
13801383
$this->collectLineage($class,$lineage);
13811384
}
13821385
}
@@ -2099,11 +2102,19 @@ private function getAutoloadFile(): ?string
20992102
returnnull;
21002103
}
21012104

2102-
privatefunctiongetClasses(Definition$definition):array
2105+
privatefunctiongetClasses(Definition$definition,string$id):array
21032106
{
21042107
$classes = [];
21052108

21062109
while ($definitioninstanceof Definition) {
2110+
foreach ($definition->getTag($this->preloadTag)as$tag) {
2111+
if (!isset($tag['class'])) {
2112+
thrownewInvalidArgumentException(sprintf('Missing attribute "class" on tag "%s" for service "%s".',$this->preloadTag,$id));
2113+
}
2114+
2115+
$classes[] =trim($tag['class'],'\\');
2116+
}
2117+
21072118
$classes[] =trim($definition->getClass(),'\\');
21082119
$factory =$definition->getFactory();
21092120

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,9 @@
187187
$container->register('errored_definition','stdClass')
188188
->addError('Service "errored_definition" is broken.');
189189

190+
$container->register('preload_sidekick','stdClass')
191+
->setPublic(true)
192+
->addTag('container.preload', ['class' =>'Some\Sidekick1'])
193+
->addTag('container.preload', ['class' =>'Some\Sidekick2']);
194+
190195
return$container;

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ digraph sc {
3636
node_tagged_iterator [label="tagged_iterator\nBar\n",shape=record,fillcolor="#eeeeee",style="filled"];
3737
node_runtime_error [label="runtime_error\nstdClass\n",shape=record,fillcolor="#eeeeee",style="filled"];
3838
node_errored_definition [label="errored_definition\nstdClass\n",shape=record,fillcolor="#eeeeee",style="filled"];
39+
node_preload_sidekick [label="preload_sidekick\nstdClass\n",shape=record,fillcolor="#eeeeee",style="filled"];
3940
node_foo2 [label="foo2\n\n",shape=record,fillcolor="#ff9999",style="filled"];
4041
node_foo3 [label="foo3\n\n",shape=record,fillcolor="#ff9999",style="filled"];
4142
node_foobaz [label="foobaz\n\n",shape=record,fillcolor="#ff9999",style="filled"];

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ $this->factories['non_shared_foo'] = function () {
308308

309309
return $this->factories['non_shared_foo']();
310310

311+
[Container%s/getPreloadSidekickService.php] => <?php
312+
313+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
314+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
315+
316+
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
317+
// Returns the public 'preload_sidekick' shared service.
318+
319+
return $this->services['preload_sidekick'] = new \stdClass();
320+
311321
[Container%s/getRuntimeErrorService.php] => <?php
312322

313323
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
@@ -412,6 +422,7 @@ class ProjectServiceContainer extends Container
412422
'method_call1' => 'getMethodCall1Service.php',
413423
'new_factory_service' => 'getNewFactoryServiceService.php',
414424
'non_shared_foo' => 'getNonSharedFooService.php',
425+
'preload_sidekick' => 'getPreloadSidekickService.php',
415426
'runtime_error' => 'getRuntimeErrorService.php',
416427
'service_from_static_method' => 'getServiceFromStaticMethodService.php',
417428
'tagged_iterator' => 'getTaggedIteratorService.php',
@@ -542,6 +553,8 @@ $classes[] = 'Foo';
542553
$classes[] = 'LazyContext';
543554
$classes[] = 'FooBarBaz';
544555
$classes[] = 'FactoryClass';
556+
$classes[] = 'Some\Sidekick1';
557+
$classes[] = 'Some\Sidekick2';
545558
$classes[] = 'Request';
546559
$classes[] = 'Symfony\Component\DependencyInjection\ContainerInterface';
547560

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class ProjectServiceContainer extends Container
7676
'method_call1' => 'getMethodCall1Service',
7777
'new_factory_service' => 'getNewFactoryServiceService',
7878
'non_shared_foo' => 'getNonSharedFooService',
79+
'preload_sidekick' => 'getPreloadSidekickService',
7980
'runtime_error' => 'getRuntimeErrorService',
8081
'service_from_static_method' => 'getServiceFromStaticMethodService',
8182
'tagged_iterator' => 'getTaggedIteratorService',
@@ -401,6 +402,16 @@ class ProjectServiceContainer extends Container
401402
return new \Bar\FooClass();
402403
}
403404

405+
/**
406+
* Gets the public 'preload_sidekick' shared service.
407+
*
408+
* @return \stdClass
409+
*/
410+
protected function getPreloadSidekickService()
411+
{
412+
return $this->services['preload_sidekick'] = new \stdClass();
413+
}
414+
404415
/**
405416
* Gets the public 'runtime_error' shared service.
406417
*
@@ -542,6 +553,8 @@ $classes[] = 'Foo';
542553
$classes[] = 'LazyContext';
543554
$classes[] = 'FooBarBaz';
544555
$classes[] = 'FactoryClass';
556+
$classes[] = 'Some\Sidekick1';
557+
$classes[] = 'Some\Sidekick2';
545558
$classes[] = 'Request';
546559
$classes[] = 'Symfony\Component\DependencyInjection\ContainerInterface';
547560

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function __construct()
4848
'lazy_context_ignore_invalid_ref' =>'getLazyContextIgnoreInvalidRefService',
4949
'method_call1' =>'getMethodCall1Service',
5050
'new_factory_service' =>'getNewFactoryServiceService',
51+
'preload_sidekick' =>'getPreloadSidekickService',
5152
'runtime_error' =>'getRuntimeErrorService',
5253
'service_from_static_method' =>'getServiceFromStaticMethodService',
5354
'tagged_iterator' =>'getTaggedIteratorService',
@@ -362,6 +363,16 @@ protected function getNewFactoryServiceService()
362363
return$instance;
363364
}
364365

366+
/**
367+
* Gets the public 'preload_sidekick' shared service.
368+
*
369+
* @return \stdClass
370+
*/
371+
protectedfunctiongetPreloadSidekickService()
372+
{
373+
return$this->services['preload_sidekick'] =new \stdClass();
374+
}
375+
365376
/**
366377
* Gets the public 'runtime_error' shared service.
367378
*

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@
148148
<argumenttype="service"id="errored_definition"/>
149149
</service>
150150
<serviceid="errored_definition"class="stdClass"/>
151+
<serviceid="preload_sidekick"class="stdClass"public="true">
152+
<tagname="container.preload"class="Some\Sidekick1"/>
153+
<tagname="container.preload"class="Some\Sidekick2"/>
154+
</service>
151155
<serviceid="Psr\Container\ContainerInterface"alias="service_container"public="false"/>
152156
<serviceid="Symfony\Component\DependencyInjection\ContainerInterface"alias="service_container"public="false"/>
153157
<serviceid="alias_for_foo"alias="foo"public="true"/>

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,9 @@ services:
177177
public:true
178178
errored_definition:
179179
class:stdClass
180+
preload_sidekick:
181+
class:stdClass
182+
tags:
183+
-{name: container.preload, class: 'Some\Sidekick1'}
184+
-{name: container.preload, class: 'Some\Sidekick2'}
185+
public:true

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp