Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[DependencyInjection] Fix fetching lazy non-shared services multiple times#50985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
nicolas-grekas merged 1 commit intosymfony:6.2fromHypeMC:fix-fetching-of-lazy-non-shared-servicesJul 16, 2023
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
[DependencyInjection] Fix fetching lazy non-shared services multiple …
…times
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commitef2626f9e56c60e1b51a6ff1027971e177dce4d1
There are no files selected for viewing
2 changes: 2 additions & 0 deletionssrc/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
69 changes: 68 additions & 1 deletionsrc/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions...fony/Component/DependencyInjection/Tests/Fixtures/php/services_non_shared_lazy_public.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <?php | ||
| use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; | ||
| use Symfony\Component\DependencyInjection\ContainerInterface; | ||
| use Symfony\Component\DependencyInjection\Container; | ||
| use Symfony\Component\DependencyInjection\Exception\LogicException; | ||
| use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; | ||
| use Symfony\Component\DependencyInjection\Exception\RuntimeException; | ||
| use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; | ||
| use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
| /** | ||
| * @internal This class has been auto-generated by the Symfony Dependency Injection Component. | ||
| */ | ||
| class Symfony_DI_PhpDumper_Service_Non_Shared_Lazy extends Container | ||
| { | ||
| protected $parameters = []; | ||
| public function __construct() | ||
| { | ||
| $this->services = $this->privates = []; | ||
| $this->methodMap = [ | ||
| 'foo' => 'getFooService', | ||
| ]; | ||
| $this->aliases = []; | ||
| } | ||
| public function compile(): void | ||
| { | ||
| throw new LogicException('You cannot compile a dumped container that was already compiled.'); | ||
| } | ||
| public function isCompiled(): bool | ||
| { | ||
| return true; | ||
| } | ||
| protected function createProxy($class, \Closure $factory) | ||
| { | ||
| return $factory(); | ||
| } | ||
| /** | ||
| * Gets the public 'foo' service. | ||
| * | ||
| * @return \Symfony\Component\DependencyInjection\Tests\Compiler\Foo | ||
| */ | ||
| protected function getFooService($lazyLoad = true) | ||
| { | ||
| $this->factories['foo'] ??= fn () => $this->getFooService(); | ||
| if (true === $lazyLoad) { | ||
| return $this->createProxy('FooGhostCf082ac', fn () => \FooGhostCf082ac::createLazyGhost($this->getFooService(...))); | ||
| } | ||
| static $include = true; | ||
| if ($include) { | ||
| include_once __DIR__.'/Fixtures/includes/foo_lazy.php'; | ||
| $include = false; | ||
| } | ||
| return $lazyLoad; | ||
| } | ||
| } | ||
| class FooGhostCf082ac extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface | ||
| { | ||
| use \Symfony\Component\VarExporter\LazyGhostTrait; | ||
| private const LAZY_OBJECT_PROPERTY_SCOPES = []; | ||
| } | ||
| // Help opcache.preload discover always-needed symbols | ||
| class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); | ||
| class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); | ||
| class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); |
88 changes: 88 additions & 0 deletions...fony/Component/DependencyInjection/Tests/Fixtures/php/services_wither_lazy_non_shared.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?php | ||
| use Symfony\Component\DependencyInjection\Argument\RewindableGenerator; | ||
| use Symfony\Component\DependencyInjection\ContainerInterface; | ||
| use Symfony\Component\DependencyInjection\Container; | ||
| use Symfony\Component\DependencyInjection\Exception\LogicException; | ||
| use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; | ||
| use Symfony\Component\DependencyInjection\Exception\RuntimeException; | ||
| use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag; | ||
| use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
| /** | ||
| * @internal This class has been auto-generated by the Symfony Dependency Injection Component. | ||
| */ | ||
| class Symfony_DI_PhpDumper_Service_Wither_Lazy_Non_Shared extends Container | ||
| { | ||
| protected $parameters = []; | ||
| public function __construct() | ||
| { | ||
| $this->services = $this->privates = []; | ||
| $this->methodMap = [ | ||
| 'wither' => 'getWitherService', | ||
| ]; | ||
| $this->aliases = []; | ||
| } | ||
| public function compile(): void | ||
| { | ||
| throw new LogicException('You cannot compile a dumped container that was already compiled.'); | ||
| } | ||
| public function isCompiled(): bool | ||
| { | ||
| return true; | ||
| } | ||
| public function getRemovedIds(): array | ||
| { | ||
| return [ | ||
| 'Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true, | ||
| ]; | ||
| } | ||
| protected function createProxy($class, \Closure $factory) | ||
| { | ||
| return $factory(); | ||
| } | ||
| /** | ||
| * Gets the public 'wither' autowired service. | ||
| * | ||
| * @return \Symfony\Component\DependencyInjection\Tests\Compiler\Wither | ||
| */ | ||
| protected function getWitherService($lazyLoad = true) | ||
| { | ||
| $this->factories['wither'] ??= fn () => $this->getWitherService(); | ||
| if (true === $lazyLoad) { | ||
| return $this->createProxy('WitherProxy8cb632f', fn () => \WitherProxy8cb632f::createLazyProxy(fn () => $this->getWitherService(false))); | ||
| } | ||
| $instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither(); | ||
| $a = ($this->privates['Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] ??= new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo()); | ||
| $instance = $instance->withFoo1($a); | ||
| $instance = $instance->withFoo2($a); | ||
| $instance->setFoo($a); | ||
| return $instance; | ||
| } | ||
| } | ||
| class WitherProxy8cb632f extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface | ||
| { | ||
| use \Symfony\Component\VarExporter\LazyProxyTrait; | ||
| private const LAZY_OBJECT_PROPERTY_SCOPES = [ | ||
| 'foo' => [parent::class, 'foo', null], | ||
| ]; | ||
| } | ||
| // Help opcache.preload discover always-needed symbols | ||
| class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); | ||
| class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); | ||
| class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.