Skip to content

Commit 0ddf6d9

Browse files
Merge branch '6.1' into 6.2
* 6.1: [Console] Correctly overwrite progressbars with different line count per step [DependencyInjection] Fix deduplicating service instances in circular graphs [Form] Make `ButtonType` handle `form_attr` option [PhpUnitBridge] Use verbose deprecation output for quiet types only when it reaches the threshold [CssSelector] Fix escape patterns
2 parents b189ea8 + 89db508 commit 0ddf6d9

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

Dumper/PhpDumper.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use Symfony\Component\DependencyInjection\Exception\LogicException;
3131
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
3232
use Symfony\Component\DependencyInjection\ExpressionLanguage;
33-
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface as ProxyDumper;
33+
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
3434
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\LazyServiceDumper;
3535
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\NullDumper;
3636
use Symfony\Component\DependencyInjection\Loader\FileLoader;
@@ -90,7 +90,8 @@ class PhpDumper extends Dumper
9090
private array $exportedVariables = [];
9191
private string $baseClass;
9292
private string $class;
93-
private ProxyDumper $proxyDumper;
93+
private DumperInterface $proxyDumper;
94+
private bool $hasProxyDumper = true;
9495

9596
public function __construct(ContainerBuilder $container)
9697
{
@@ -104,9 +105,10 @@ public function __construct(ContainerBuilder $container)
104105
/**
105106
* Sets the dumper to be used when dumping proxies in the generated container.
106107
*/
107-
public function setProxyDumper(ProxyDumper $proxyDumper)
108+
public function setProxyDumper(DumperInterface $proxyDumper)
108109
{
109110
$this->proxyDumper = $proxyDumper;
111+
$this->hasProxyDumper = !$proxyDumper instanceof NullDumper;
110112
}
111113

112114
/**
@@ -165,7 +167,7 @@ public function dump(array $options = []): string|array
165167

166168
$this->initializeMethodNamesMap('Container' === $baseClass ? Container::class : $baseClass);
167169

168-
if ($this->getProxyDumper() instanceof NullDumper) {
170+
if (!$this->hasProxyDumper) {
169171
(new AnalyzeServiceReferencesPass(true, false))->process($this->container);
170172
(new CheckCircularReferencesPass())->process($this->container);
171173
}
@@ -390,14 +392,14 @@ class %s extends {$options['class']}
390392
/**
391393
* Retrieves the currently set proxy dumper or instantiates one.
392394
*/
393-
private function getProxyDumper(): ProxyDumper
395+
private function getProxyDumper(): DumperInterface
394396
{
395397
return $this->proxyDumper ??= new LazyServiceDumper($this->class);
396398
}
397399

398400
private function analyzeReferences()
399401
{
400-
(new AnalyzeServiceReferencesPass(false, !$this->getProxyDumper() instanceof NullDumper))->process($this->container);
402+
(new AnalyzeServiceReferencesPass(false, $this->hasProxyDumper))->process($this->container);
401403
$checkedNodes = [];
402404
$this->circularReferences = [];
403405
$this->singleUsePrivateIds = [];
@@ -424,13 +426,13 @@ private function collectCircularReferences(string $sourceId, array $edges, array
424426
foreach ($edges as $edge) {
425427
$node = $edge->getDestNode();
426428
$id = $node->getId();
427-
if ($sourceId === $id || !$node->getValue() instanceof Definition || $edge->isLazy() || $edge->isWeak()) {
429+
if ($sourceId === $id || !$node->getValue() instanceof Definition || $edge->isWeak()) {
428430
continue;
429431
}
430432

431433
if (isset($path[$id])) {
432434
$loop = null;
433-
$loopByConstructor = $edge->isReferencedByConstructor();
435+
$loopByConstructor = $edge->isReferencedByConstructor() && !$edge->isLazy();
434436
$pathInLoop = [$id, []];
435437
foreach ($path as $k => $pathByConstructor) {
436438
if (null !== $loop) {
@@ -444,7 +446,7 @@ private function collectCircularReferences(string $sourceId, array $edges, array
444446
}
445447
$this->addCircularReferences($id, $loop, $loopByConstructor);
446448
} elseif (!isset($checkedNodes[$id])) {
447-
$this->collectCircularReferences($id, $node->getOutEdges(), $checkedNodes, $loops, $path, $edge->isReferencedByConstructor());
449+
$this->collectCircularReferences($id, $node->getOutEdges(), $checkedNodes, $loops, $path, $edge->isReferencedByConstructor() && !$edge->isLazy());
448450
} elseif (isset($loops[$id])) {
449451
// we already had detected loops for this edge
450452
// let's check if we have a common ancestor in one of the detected loops
@@ -465,7 +467,7 @@ private function collectCircularReferences(string $sourceId, array $edges, array
465467

466468
// we can now build the loop
467469
$loop = null;
468-
$loopByConstructor = $edge->isReferencedByConstructor();
470+
$loopByConstructor = $edge->isReferencedByConstructor() && !$edge->isLazy();
469471
foreach ($fillPath as $k => $pathByConstructor) {
470472
if (null !== $loop) {
471473
$loop[] = $k;
@@ -968,7 +970,7 @@ private function addInlineReference(string $id, Definition $definition, string $
968970
return '';
969971
}
970972

971-
$hasSelfRef = isset($this->circularReferences[$id][$targetId]) && !isset($this->definitionVariables[$definition]);
973+
$hasSelfRef = isset($this->circularReferences[$id][$targetId]) && !isset($this->definitionVariables[$definition]) && !($this->hasProxyDumper && $definition->isLazy());
972974

973975
if ($hasSelfRef && !$forConstructor && !$forConstructor = !$this->circularReferences[$id][$targetId]) {
974976
$code = $this->addInlineService($id, $definition, $definition);
@@ -1011,7 +1013,7 @@ private function addInlineService(string $id, Definition $definition, Definition
10111013

10121014
if ($isSimpleInstance = $isRootInstance = null === $inlineDef) {
10131015
foreach ($this->serviceCalls as $targetId => [$callCount, $behavior, $byConstructor]) {
1014-
if ($byConstructor && isset($this->circularReferences[$id][$targetId]) && !$this->circularReferences[$id][$targetId]) {
1016+
if ($byConstructor && isset($this->circularReferences[$id][$targetId]) && !$this->circularReferences[$id][$targetId] && !($this->hasProxyDumper && $definition->isLazy())) {
10151017
$code .= $this->addInlineReference($id, $definition, $targetId, $forConstructor);
10161018
}
10171019
}
@@ -1291,7 +1293,7 @@ protected function load($file, $lazyLoad = true)
12911293
}
12921294

12931295
foreach ($this->container->getDefinitions() as $definition) {
1294-
if (!$definition->isLazy() || $this->getProxyDumper() instanceof NullDumper) {
1296+
if (!$definition->isLazy() || !$this->hasProxyDumper) {
12951297
continue;
12961298
}
12971299

@@ -1469,7 +1471,7 @@ private function addInlineRequires(bool $hasProxyClasses): string
14691471
foreach ($hotPathServices as $id => $tags) {
14701472
$definition = $this->container->getDefinition($id);
14711473

1472-
if ($definition->isLazy() && !$this->getProxyDumper() instanceof NullDumper) {
1474+
if ($definition->isLazy() && $this->hasProxyDumper) {
14731475
continue;
14741476
}
14751477

@@ -2259,7 +2261,7 @@ private function isProxyCandidate(Definition $definition, ?bool &$asGhostObject,
22592261
{
22602262
$asGhostObject = false;
22612263

2262-
if (!$definition->isLazy() || ($proxyDumper = $this->getProxyDumper()) instanceof NullDumper) {
2264+
if (!$definition->isLazy() || !$this->hasProxyDumper) {
22632265
return null;
22642266
}
22652267

@@ -2268,6 +2270,6 @@ private function isProxyCandidate(Definition $definition, ?bool &$asGhostObject,
22682270
->setClass($bag->resolveValue($definition->getClass()))
22692271
->setTags(($definition->hasTag('proxy') ? ['proxy' => $bag->resolveValue($definition->getTag('proxy'))] : []) + $definition->getTags());
22702272

2271-
return $proxyDumper->isProxyCandidate($definition, $asGhostObject, $id) ? $definition : null;
2273+
return $this->getProxyDumper()->isProxyCandidate($definition, $asGhostObject, $id) ? $definition : null;
22722274
}
22732275
}

Tests/Fixtures/php/services_almost_circular_private.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,13 @@ protected function getBar6Service()
489489
*/
490490
protected function getDoctrine_ListenerService()
491491
{
492-
return $this->privates['doctrine.listener'] = new \stdClass(($this->services['doctrine.entity_manager'] ?? $this->getDoctrine_EntityManagerService()));
492+
$a = ($this->services['doctrine.entity_manager'] ?? $this->getDoctrine_EntityManagerService());
493+
494+
if (isset($this->privates['doctrine.listener'])) {
495+
return $this->privates['doctrine.listener'];
496+
}
497+
498+
return $this->privates['doctrine.listener'] = new \stdClass($a);
493499
}
494500

495501
/**

Tests/Fixtures/php/services_almost_circular_public.php

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,16 @@ protected function getDoctrine_EntityListenerResolverService()
283283
*/
284284
protected function getDoctrine_EntityManagerService()
285285
{
286-
$a = new \stdClass();
287-
$a->resolver = ($this->services['doctrine.entity_listener_resolver'] ?? $this->getDoctrine_EntityListenerResolverService());
288-
$a->flag = 'ok';
286+
$a = ($this->services['doctrine.entity_listener_resolver'] ?? $this->getDoctrine_EntityListenerResolverService());
287+
288+
if (isset($this->services['doctrine.entity_manager'])) {
289+
return $this->services['doctrine.entity_manager'];
290+
}
291+
$b = new \stdClass();
292+
$b->resolver = $a;
293+
$b->flag = 'ok';
289294

290-
return $this->services['doctrine.entity_manager'] = \FactoryChecker::create($a);
295+
return $this->services['doctrine.entity_manager'] = \FactoryChecker::create($b);
291296
}
292297

293298
/**
@@ -297,7 +302,13 @@ protected function getDoctrine_EntityManagerService()
297302
*/
298303
protected function getDoctrine_ListenerService()
299304
{
300-
return $this->services['doctrine.listener'] = new \stdClass(($this->services['doctrine.entity_manager'] ?? $this->getDoctrine_EntityManagerService()));
305+
$a = ($this->services['doctrine.entity_manager'] ?? $this->getDoctrine_EntityManagerService());
306+
307+
if (isset($this->services['doctrine.listener'])) {
308+
return $this->services['doctrine.listener'];
309+
}
310+
311+
return $this->services['doctrine.listener'] = new \stdClass($a);
301312
}
302313

303314
/**
@@ -493,7 +504,13 @@ protected function getLoggerService()
493504
*/
494505
protected function getMailer_TransportService()
495506
{
496-
return $this->services['mailer.transport'] = ($this->services['mailer.transport_factory'] ?? $this->getMailer_TransportFactoryService())->create();
507+
$a = ($this->services['mailer.transport_factory'] ?? $this->getMailer_TransportFactoryService());
508+
509+
if (isset($this->services['mailer.transport'])) {
510+
return $this->services['mailer.transport'];
511+
}
512+
513+
return $this->services['mailer.transport'] = $a->create();
497514
}
498515

499516
/**
@@ -516,7 +533,13 @@ protected function getMailer_TransportFactoryService()
516533
*/
517534
protected function getMailer_TransportFactory_AmazonService()
518535
{
519-
return $this->services['mailer.transport_factory.amazon'] = new \stdClass(($this->services['monolog.logger_2'] ?? $this->getMonolog_Logger2Service()));
536+
$a = ($this->services['monolog.logger_2'] ?? $this->getMonolog_Logger2Service());
537+
538+
if (isset($this->services['mailer.transport_factory.amazon'])) {
539+
return $this->services['mailer.transport_factory.amazon'];
540+
}
541+
542+
return $this->services['mailer.transport_factory.amazon'] = new \stdClass($a);
520543
}
521544

522545
/**

0 commit comments

Comments
 (0)