From b62ee86d304640450dbb4722e405c4b5ef5ebb80 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 24 Mar 2020 23:00:18 +0100 Subject: [PATCH] [DI] add tags `container.preload`/`.no_preload` to declare extra classes to preload/services to not preload --- .../Compiler/UnusedTagsPass.php | 2 ++ .../FrameworkExtension.php | 6 +++-- .../Resources/config/annotations.xml | 1 + .../Resources/config/cache_debug.xml | 1 + .../Resources/config/console.xml | 2 ++ .../Resources/config/routing.xml | 1 + .../Resources/config/serializer.xml | 1 + .../Resources/config/services.xml | 1 + .../Resources/config/translation.xml | 1 + .../Resources/config/validator.xml | 1 + .../Resources/config/security.xml | 1 + .../TwigBundle/Resources/config/twig.xml | 9 +++++++ src/Symfony/Bundle/TwigBundle/TwigBundle.php | 14 ---------- .../AddConsoleCommandPass.php | 6 ++++- .../DependencyInjection/CHANGELOG.md | 1 + .../DependencyInjection/Dumper/PhpDumper.php | 27 +++++++++++++------ .../Tests/Fixtures/config/services9.php | 4 +++ .../Tests/Fixtures/containers/container9.php | 5 ++++ .../Tests/Fixtures/graphviz/services9.dot | 1 + .../Tests/Fixtures/php/services9_as_files.txt | 13 +++++++++ .../Tests/Fixtures/php/services9_compiled.php | 11 ++++++++ .../php/services9_inlined_factories.txt | 13 +++++++++ .../php/services_errored_definition.php | 11 ++++++++ .../Tests/Fixtures/xml/services9.xml | 4 +++ .../Tests/Fixtures/yaml/services9.yml | 6 +++++ .../ExpressionLanguage/ExpressionLanguage.php | 3 +++ .../Component/Translation/Translator.php | 3 +++ 27 files changed, 124 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php index 99f1d5af447ea..5d1e803ab392f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/UnusedTagsPass.php @@ -32,6 +32,8 @@ class UnusedTagsPass implements CompilerPassInterface 'container.env_var_loader', 'container.env_var_processor', 'container.hot_path', + 'container.no_preload', + 'container.preload', 'container.reversible', 'container.service_locator', 'container.service_locator_context', diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index df8416100c816..0c6f80466a0cb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -408,7 +408,8 @@ public function load(array $configs, ContainerBuilder $container) } $container->registerForAutoconfiguration(Command::class) - ->addTag('console.command'); + ->addTag('console.command') + ->addTag('container.no_preload'); $container->registerForAutoconfiguration(ResourceCheckerInterface::class) ->addTag('config_cache.resource_checker'); $container->registerForAutoconfiguration(EnvVarLoaderInterface::class) @@ -434,7 +435,8 @@ public function load(array $configs, ContainerBuilder $container) $container->registerForAutoconfiguration(CacheClearerInterface::class) ->addTag('kernel.cache_clearer'); $container->registerForAutoconfiguration(CacheWarmerInterface::class) - ->addTag('kernel.cache_warmer'); + ->addTag('kernel.cache_warmer') + ->addTag('container.no_preload'); $container->registerForAutoconfiguration(EventSubscriberInterface::class) ->addTag('kernel.event_subscriber'); $container->registerForAutoconfiguration(LocaleAwareInterface::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml index 0ce6bf6594e31..7eac708e83984 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml @@ -34,6 +34,7 @@ + %kernel.cache_dir%/annotations.php #^Symfony\\(?:Component\\HttpKernel\\|Bundle\\FrameworkBundle\\Controller\\(?!.*Controller$))# diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml index d4a7396c60d67..d5a099d7b2e0c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/cache_debug.xml @@ -20,6 +20,7 @@ cache.serializer + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml index cbd43ac7a6a93..3ef3108b45d49 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml @@ -11,10 +11,12 @@ + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index 9c9eec1e152b5..e4105a59f4626 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -101,6 +101,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml index 0dbc388ddffcb..5d7d536deece8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.xml @@ -107,6 +107,7 @@ %serializer.mapping.cache.file% + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index d9035ca7b8672..0c22d637d5a10 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -66,6 +66,7 @@ + %kernel.debug% %kernel.cache_dir%/%kernel.container_class%Deprecations.log diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml index 3c158abb02358..4d056a01a3247 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml @@ -139,6 +139,7 @@ + diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml index 070908f3db351..01c8b36de83ea 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.xml @@ -36,6 +36,7 @@ %validator.mapping.cache.file% + diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml index 1f0e64b803484..2575e5f904d25 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml @@ -218,6 +218,7 @@ + diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index ff23962cd3b54..47603bc4fd9c9 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -18,6 +18,14 @@ + + + + + + + + @@ -37,6 +45,7 @@ + diff --git a/src/Symfony/Bundle/TwigBundle/TwigBundle.php b/src/Symfony/Bundle/TwigBundle/TwigBundle.php index 58760b65ae932..3910dd5e2e389 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigBundle.php +++ b/src/Symfony/Bundle/TwigBundle/TwigBundle.php @@ -19,20 +19,6 @@ use Symfony\Component\DependencyInjection\Compiler\PassConfig; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -use Twig\Cache\FilesystemCache; -use Twig\Extension\CoreExtension; -use Twig\Extension\EscaperExtension; -use Twig\Extension\OptimizerExtension; -use Twig\Extension\StagingExtension; -use Twig\ExtensionSet; - -// Help opcache.preload discover always-needed symbols -class_exists(FilesystemCache::class); -class_exists(CoreExtension::class); -class_exists(EscaperExtension::class); -class_exists(OptimizerExtension::class); -class_exists(StagingExtension::class); -class_exists(ExtensionSet::class); /** * Bundle. diff --git a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php index 666c8fa5987cf..f4cd3874c5759 100644 --- a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php +++ b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php @@ -28,11 +28,13 @@ class AddConsoleCommandPass implements CompilerPassInterface { private $commandLoaderServiceId; private $commandTag; + private $noPreloadTag; - public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command') + public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload') { $this->commandLoaderServiceId = $commandLoaderServiceId; $this->commandTag = $commandTag; + $this->noPreloadTag = $noPreloadTag; } public function process(ContainerBuilder $container) @@ -44,6 +46,7 @@ public function process(ContainerBuilder $container) foreach ($commandServices as $id => $tags) { $definition = $container->getDefinition($id); + $definition->addTag($this->noPreloadTag); $class = $container->getParameterBag()->resolveValue($definition->getClass()); if (isset($tags[0]['command'])) { @@ -91,6 +94,7 @@ public function process(ContainerBuilder $container) $container ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) ->setPublic(true) + ->addTag($this->noPreloadTag) ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); $container->setParameter('console.command.ids', $serviceIds); diff --git a/src/Symfony/Component/DependencyInjection/CHANGELOG.md b/src/Symfony/Component/DependencyInjection/CHANGELOG.md index 0bacf3d561da7..3d90c4ecdadee 100644 --- a/src/Symfony/Component/DependencyInjection/CHANGELOG.md +++ b/src/Symfony/Component/DependencyInjection/CHANGELOG.md @@ -7,6 +7,7 @@ CHANGELOG * added support to autowire public typed properties in php 7.4 * added support for defining method calls, a configurator, and property setters in `InlineServiceConfigurator` * added possibility to define abstract service arguments + * added tags `container.preload`/`.no_preload` to declare extra classes to preload/services to not preload 5.0.0 ----- diff --git a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php index abba94468becd..ee6dd61816a6f 100644 --- a/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php +++ b/src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php @@ -78,6 +78,7 @@ class PhpDumper extends Dumper private $namespace; private $asFiles; private $hotPathTag; + private $preloadTag; private $inlineFactories; private $inlineRequires; private $inlinedRequires = []; @@ -143,6 +144,7 @@ public function dump(array $options = []) 'as_files' => false, 'debug' => true, 'hot_path_tag' => 'container.hot_path', + 'preload_tags' => ['container.preload', 'container.no_preload'], 'inline_factories_parameter' => 'container.dumper.inline_factories', 'inline_class_loader_parameter' => 'container.dumper.inline_class_loader', 'preload_classes' => [], @@ -154,6 +156,7 @@ public function dump(array $options = []) $this->namespace = $options['namespace']; $this->asFiles = $options['as_files']; $this->hotPathTag = $options['hot_path_tag']; + $this->preloadTags = $options['preload_tags']; $this->inlineFactories = $this->asFiles && $options['inline_factories_parameter'] && (!$this->container->hasParameter($options['inline_factories_parameter']) || $this->container->getParameter($options['inline_factories_parameter'])); $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'])); $this->serviceLocatorTag = $options['service_locator_tag']; @@ -560,7 +563,7 @@ private function addServiceInclude(string $cId, Definition $definition): string $lineage = []; foreach ($this->inlinedDefinitions as $def) { if (!$def->isDeprecated()) { - foreach ($this->getClasses($def) as $class) { + foreach ($this->getClasses($def, $cId) as $class) { $this->collectLineage($class, $lineage); } } @@ -572,7 +575,7 @@ private function addServiceInclude(string $cId, Definition $definition): string && $this->container->has($id) && $this->isTrivialInstance($def = $this->container->findDefinition($id)) ) { - foreach ($this->getClasses($def) as $class) { + foreach ($this->getClasses($def, $cId) as $class) { $this->collectLineage($class, $lineage); } } @@ -824,9 +827,9 @@ protected function {$methodName}($lazyInitialization) if ($definition->isDeprecated()) { $code .= sprintf(" trigger_deprecation('', '', %s);\n\n", $this->export($definition->getDeprecationMessage($id))); - } else { + } elseif (!$definition->hasTag($this->preloadTags[1])) { foreach ($this->inlinedDefinitions as $def) { - foreach ($this->getClasses($def) as $class) { + foreach ($this->getClasses($def, $id) as $class) { $this->preload[$class] = $class; } } @@ -988,10 +991,10 @@ private function addServices(array &$services = null): string foreach ($definitions as $id => $definition) { if (!$definition->isSynthetic()) { $services[$id] = $this->addService($id, $definition); - } else { + } elseif (!$definition->hasTag($this->preloadTags[1])) { $services[$id] = null; - foreach ($this->getClasses($definition) as $class) { + foreach ($this->getClasses($definition, $id) as $class) { $this->preload[$class] = $class; } } @@ -1376,7 +1379,7 @@ private function addInlineRequires(): string $inlinedDefinitions = $this->getDefinitionsFromArguments([$definition]); foreach ($inlinedDefinitions as $def) { - foreach ($this->getClasses($def) as $class) { + foreach ($this->getClasses($def, $id) as $class) { $this->collectLineage($class, $lineage); } } @@ -2099,11 +2102,19 @@ private function getAutoloadFile(): ?string return null; } - private function getClasses(Definition $definition): array + private function getClasses(Definition $definition, string $id): array { $classes = []; while ($definition instanceof Definition) { + foreach ($definition->getTag($this->preloadTags[0]) as $tag) { + if (!isset($tag['class'])) { + throw new InvalidArgumentException(sprintf('Missing attribute "class" on tag "%s" for service "%s".', $this->preloadTags[0], $id)); + } + + $classes[] = trim($tag['class'], '\\'); + } + $classes[] = trim($definition->getClass(), '\\'); $factory = $definition->getFactory(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php index 7c070ef64f450..c0dca53ada6b2 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php @@ -134,6 +134,10 @@ ->args([new Reference('errored_definition', ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE)]) ->public(); $s->set('errored_definition', 'stdClass')->private(); + $s->set('preload_sidekick', 'stdClass') + ->tag('container.preload', ['class' => 'Some\Sidekick1']) + ->tag('container.preload', ['class' => 'Some\Sidekick2']) + ->public(); $s->alias('alias_for_foo', 'foo')->private()->public(); $s->alias('alias_for_alias', ref('alias_for_foo')); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php index 6ae7f7161ab7f..36f0fe6fc6f19 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php @@ -187,4 +187,9 @@ $container->register('errored_definition', 'stdClass') ->addError('Service "errored_definition" is broken.'); +$container->register('preload_sidekick', 'stdClass') + ->setPublic(true) + ->addTag('container.preload', ['class' => 'Some\Sidekick1']) + ->addTag('container.preload', ['class' => 'Some\Sidekick2']); + return $container; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot index 5cf170fddb8c3..994506f25a4b4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot @@ -36,6 +36,7 @@ digraph sc { node_tagged_iterator [label="tagged_iterator\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_runtime_error [label="runtime_error\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_errored_definition [label="errored_definition\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; + node_preload_sidekick [label="preload_sidekick\nstdClass\n", shape=record, fillcolor="#eeeeee", style="filled"]; node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"]; node_foobaz [label="foobaz\n\n", shape=record, fillcolor="#ff9999", style="filled"]; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt index 47d6594970159..a26b2e767eca1 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt @@ -308,6 +308,16 @@ $this->factories['non_shared_foo'] = function () { return $this->factories['non_shared_foo'](); + [Container%s/getPreloadSidekickService.php] => services['preload_sidekick'] = new \stdClass(); + [Container%s/getRuntimeErrorService.php] => 'getMethodCall1Service.php', 'new_factory_service' => 'getNewFactoryServiceService.php', 'non_shared_foo' => 'getNonSharedFooService.php', + 'preload_sidekick' => 'getPreloadSidekickService.php', 'runtime_error' => 'getRuntimeErrorService.php', 'service_from_static_method' => 'getServiceFromStaticMethodService.php', 'tagged_iterator' => 'getTaggedIteratorService.php', @@ -542,6 +553,8 @@ $classes[] = 'Foo'; $classes[] = 'LazyContext'; $classes[] = 'FooBarBaz'; $classes[] = 'FactoryClass'; +$classes[] = 'Some\Sidekick1'; +$classes[] = 'Some\Sidekick2'; $classes[] = 'Request'; $classes[] = 'Symfony\Component\DependencyInjection\ContainerInterface'; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php index d448e7d5bcf8a..d3881ab3dfb5d 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php @@ -48,6 +48,7 @@ public function __construct() 'lazy_context_ignore_invalid_ref' => 'getLazyContextIgnoreInvalidRefService', 'method_call1' => 'getMethodCall1Service', 'new_factory_service' => 'getNewFactoryServiceService', + 'preload_sidekick' => 'getPreloadSidekickService', 'runtime_error' => 'getRuntimeErrorService', 'service_from_static_method' => 'getServiceFromStaticMethodService', 'tagged_iterator' => 'getTaggedIteratorService', @@ -362,6 +363,16 @@ protected function getNewFactoryServiceService() return $instance; } + /** + * Gets the public 'preload_sidekick' shared service. + * + * @return \stdClass + */ + protected function getPreloadSidekickService() + { + return $this->services['preload_sidekick'] = new \stdClass(); + } + /** * Gets the public 'runtime_error' shared service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt index 6e12f7c57d751..1fce0d3016c02 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_inlined_factories.txt @@ -76,6 +76,7 @@ class ProjectServiceContainer extends Container 'method_call1' => 'getMethodCall1Service', 'new_factory_service' => 'getNewFactoryServiceService', 'non_shared_foo' => 'getNonSharedFooService', + 'preload_sidekick' => 'getPreloadSidekickService', 'runtime_error' => 'getRuntimeErrorService', 'service_from_static_method' => 'getServiceFromStaticMethodService', 'tagged_iterator' => 'getTaggedIteratorService', @@ -401,6 +402,16 @@ class ProjectServiceContainer extends Container return new \Bar\FooClass(); } + /** + * Gets the public 'preload_sidekick' shared service. + * + * @return \stdClass + */ + protected function getPreloadSidekickService() + { + return $this->services['preload_sidekick'] = new \stdClass(); + } + /** * Gets the public 'runtime_error' shared service. * @@ -542,6 +553,8 @@ $classes[] = 'Foo'; $classes[] = 'LazyContext'; $classes[] = 'FooBarBaz'; $classes[] = 'FactoryClass'; +$classes[] = 'Some\Sidekick1'; +$classes[] = 'Some\Sidekick2'; $classes[] = 'Request'; $classes[] = 'Symfony\Component\DependencyInjection\ContainerInterface'; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php index 1e7ce2f2c95c8..730c7303cf15c 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php @@ -48,6 +48,7 @@ public function __construct() 'lazy_context_ignore_invalid_ref' => 'getLazyContextIgnoreInvalidRefService', 'method_call1' => 'getMethodCall1Service', 'new_factory_service' => 'getNewFactoryServiceService', + 'preload_sidekick' => 'getPreloadSidekickService', 'runtime_error' => 'getRuntimeErrorService', 'service_from_static_method' => 'getServiceFromStaticMethodService', 'tagged_iterator' => 'getTaggedIteratorService', @@ -362,6 +363,16 @@ protected function getNewFactoryServiceService() return $instance; } + /** + * Gets the public 'preload_sidekick' shared service. + * + * @return \stdClass + */ + protected function getPreloadSidekickService() + { + return $this->services['preload_sidekick'] = new \stdClass(); + } + /** * Gets the public 'runtime_error' shared service. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml index 55ec20ee10059..e2d9bc945ed44 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml @@ -148,6 +148,10 @@ + + + + diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml index fd2be046f8cd6..1f0cf6160da18 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml @@ -177,3 +177,9 @@ services: public: true errored_definition: class: stdClass + preload_sidekick: + class: stdClass + tags: + - {name: container.preload, class: 'Some\Sidekick1'} + - {name: container.preload, class: 'Some\Sidekick2'} + public: true diff --git a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php index e9e36e9f6452b..b2e58a08034b5 100644 --- a/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php +++ b/src/Symfony/Component/ExpressionLanguage/ExpressionLanguage.php @@ -14,6 +14,9 @@ use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; +// Help opcache.preload discover always-needed symbols +class_exists(ParsedExpression::class); + /** * Allows to compile and evaluate expressions written in your own DSL. * diff --git a/src/Symfony/Component/Translation/Translator.php b/src/Symfony/Component/Translation/Translator.php index 24910f0827c04..cefd5026bb674 100644 --- a/src/Symfony/Component/Translation/Translator.php +++ b/src/Symfony/Component/Translation/Translator.php @@ -24,6 +24,9 @@ use Symfony\Contracts\Translation\LocaleAwareInterface; use Symfony\Contracts\Translation\TranslatorInterface; +// Help opcache.preload discover always-needed symbols +class_exists(MessageCatalogue::class); + /** * @author Fabien Potencier */