Skip to content

Commit deb6aa0

Browse files
committed
Merge branch '5.1' into 5.x
2 parents 6f284b0 + 50da552 commit deb6aa0

File tree

8 files changed

+171
-4
lines changed

8 files changed

+171
-4
lines changed

ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,20 +1167,20 @@ private function doResolveServices($value, array &$inlineServices = [], bool $is
11671167
return $this->resolveServices($reference);
11681168
};
11691169
} elseif ($value instanceof IteratorArgument) {
1170-
$value = new RewindableGenerator(function () use ($value) {
1170+
$value = new RewindableGenerator(function () use ($value, &$inlineServices) {
11711171
foreach ($value->getValues() as $k => $v) {
11721172
foreach (self::getServiceConditionals($v) as $s) {
11731173
if (!$this->has($s)) {
11741174
continue 2;
11751175
}
11761176
}
11771177
foreach (self::getInitializedConditionals($v) as $s) {
1178-
if (!$this->doGet($s, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE)) {
1178+
if (!$this->doGet($s, ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE, $inlineServices)) {
11791179
continue 2;
11801180
}
11811181
}
11821182

1183-
yield $k => $this->resolveServices($v);
1183+
yield $k => $this->doResolveServices($v, $inlineServices);
11841184
}
11851185
}, function () use ($value): int {
11861186
$count = 0;

Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ private function collectCircularReferences(string $sourceId, array $edges, array
471471
foreach ($edges as $edge) {
472472
$node = $edge->getDestNode();
473473
$id = $node->getId();
474-
if (!$node->getValue() instanceof Definition || $sourceId === $id || $edge->isLazy() || $edge->isWeak()) {
474+
if (!$node->getValue() instanceof Definition || $sourceId === $id || $edge->isWeak()) {
475475
continue;
476476
}
477477

Tests/ContainerBuilderTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,10 @@ public function testUninitializedReference()
13931393
public function testAlmostCircular($visibility)
13941394
{
13951395
$container = include __DIR__.'/Fixtures/containers/container_almost_circular.php';
1396+
$container->compile();
1397+
1398+
$logger = $container->get('monolog.logger');
1399+
$this->assertEquals(new \stdClass(), $logger->handler);
13961400

13971401
$foo = $container->get('foo');
13981402
$this->assertSame($foo, $foo->bar->foobar->foo);

Tests/Dumper/PhpDumperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ public function testAlmostCircular($visibility)
10541054

10551055
$container = new $container();
10561056

1057+
$logger = $container->get('monolog.logger');
1058+
$this->assertEquals(new \stdClass(), $logger->handler);
1059+
10571060
$foo = $container->get('foo');
10581061
$this->assertSame($foo, $foo->bar->foobar->foo);
10591062

Tests/Fixtures/containers/container_almost_circular.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
34
use Symfony\Component\DependencyInjection\ContainerBuilder;
45
use Symfony\Component\DependencyInjection\Definition;
56
use Symfony\Component\DependencyInjection\Reference;
@@ -8,6 +9,24 @@
89
$public = 'public' === $visibility;
910
$container = new ContainerBuilder();
1011

12+
// monolog-like + handler that require monolog
13+
14+
$container->register('monolog.logger', 'stdClass')->setPublic(true)
15+
->setProperty('handler', new Reference('mailer.transport'));
16+
17+
$container->register('mailer.transport', 'stdClass')->setPublic($public)
18+
->setFactory([new Reference('mailer.transport_factory'), 'create']);
19+
20+
$container->register('mailer.transport_factory', FactoryCircular::class)->setPublic($public)
21+
->addArgument(new TaggedIteratorArgument('mailer.transport'));
22+
23+
$container->register('mailer.transport_factory.amazon', 'stdClass')->setPublic($public)
24+
->addArgument(new Reference('monolog.logger_2'))
25+
->addTag('mailer.transport');
26+
27+
$container->register('monolog.logger_2', 'stdClass')->setPublic($public)
28+
->setProperty('handler', new Reference('mailer.transport'));
29+
1130
// same visibility for deps
1231

1332
$container->register('foo', FooCircular::class)->setPublic(true)

Tests/Fixtures/includes/classes.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,23 @@ public function __construct($lazyValues, $lazyEmptyValues)
111111
}
112112
}
113113

114+
class FactoryCircular
115+
{
116+
public $services;
117+
118+
public function __construct($services)
119+
{
120+
$this->services = $services;
121+
}
122+
123+
public function create()
124+
{
125+
foreach ($this->services as $service) {
126+
return $service;
127+
}
128+
}
129+
}
130+
114131
class FoobarCircular
115132
{
116133
public function __construct(FooCircular $foo)

Tests/Fixtures/php/services_almost_circular_private.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct()
3636
'manager' => 'getManagerService',
3737
'manager2' => 'getManager2Service',
3838
'manager3' => 'getManager3Service',
39+
'monolog.logger' => 'getMonolog_LoggerService',
3940
'root' => 'getRootService',
4041
'subscriber' => 'getSubscriberService',
4142
];
@@ -77,7 +78,11 @@ public function getRemovedIds(): array
7778
'level5' => true,
7879
'level6' => true,
7980
'logger2' => true,
81+
'mailer.transport' => true,
82+
'mailer.transport_factory' => true,
83+
'mailer.transport_factory.amazon' => true,
8084
'manager4' => true,
85+
'monolog.logger_2' => true,
8186
'multiuse1' => true,
8287
'subscriber2' => true,
8388
];
@@ -352,6 +357,20 @@ protected function getManager3Service($lazyLoad = true)
352357
return $this->services['manager3'] = new \stdClass($b);
353358
}
354359

360+
/**
361+
* Gets the public 'monolog.logger' shared service.
362+
*
363+
* @return \stdClass
364+
*/
365+
protected function getMonolog_LoggerService()
366+
{
367+
$this->services['monolog.logger'] = $instance = new \stdClass();
368+
369+
$instance->handler = ($this->privates['mailer.transport'] ?? $this->getMailer_TransportService());
370+
371+
return $instance;
372+
}
373+
355374
/**
356375
* Gets the public 'root' shared service.
357376
*
@@ -416,6 +435,34 @@ protected function getLevel5Service()
416435
return $instance;
417436
}
418437

438+
/**
439+
* Gets the private 'mailer.transport' shared service.
440+
*
441+
* @return \stdClass
442+
*/
443+
protected function getMailer_TransportService()
444+
{
445+
return $this->privates['mailer.transport'] = (new \FactoryCircular(new RewindableGenerator(function () {
446+
yield 0 => ($this->privates['mailer.transport_factory.amazon'] ?? $this->getMailer_TransportFactory_AmazonService());
447+
}, 1)))->create();
448+
}
449+
450+
/**
451+
* Gets the private 'mailer.transport_factory.amazon' shared service.
452+
*
453+
* @return \stdClass
454+
*/
455+
protected function getMailer_TransportFactory_AmazonService()
456+
{
457+
$a = new \stdClass();
458+
459+
$this->privates['mailer.transport_factory.amazon'] = $instance = new \stdClass($a);
460+
461+
$a->handler = ($this->privates['mailer.transport'] ?? $this->getMailer_TransportService());
462+
463+
return $instance;
464+
}
465+
419466
/**
420467
* Gets the private 'manager4' shared service.
421468
*

Tests/Fixtures/php/services_almost_circular_public.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ public function __construct()
4242
'listener3' => 'getListener3Service',
4343
'listener4' => 'getListener4Service',
4444
'logger' => 'getLoggerService',
45+
'mailer.transport' => 'getMailer_TransportService',
46+
'mailer.transport_factory' => 'getMailer_TransportFactoryService',
47+
'mailer.transport_factory.amazon' => 'getMailer_TransportFactory_AmazonService',
4548
'manager' => 'getManagerService',
4649
'manager2' => 'getManager2Service',
4750
'manager3' => 'getManager3Service',
51+
'monolog.logger' => 'getMonolog_LoggerService',
52+
'monolog.logger_2' => 'getMonolog_Logger2Service',
4853
'root' => 'getRootService',
4954
'subscriber' => 'getSubscriberService',
5055
];
@@ -434,6 +439,50 @@ protected function getLoggerService()
434439
return $instance;
435440
}
436441

442+
/**
443+
* Gets the public 'mailer.transport' shared service.
444+
*
445+
* @return \stdClass
446+
*/
447+
protected function getMailer_TransportService()
448+
{
449+
$a = ($this->services['mailer.transport_factory'] ?? $this->getMailer_TransportFactoryService());
450+
451+
if (isset($this->services['mailer.transport'])) {
452+
return $this->services['mailer.transport'];
453+
}
454+
455+
return $this->services['mailer.transport'] = $a->create();
456+
}
457+
458+
/**
459+
* Gets the public 'mailer.transport_factory' shared service.
460+
*
461+
* @return \FactoryCircular
462+
*/
463+
protected function getMailer_TransportFactoryService()
464+
{
465+
return $this->services['mailer.transport_factory'] = new \FactoryCircular(new RewindableGenerator(function () {
466+
yield 0 => ($this->services['mailer.transport_factory.amazon'] ?? $this->getMailer_TransportFactory_AmazonService());
467+
}, 1));
468+
}
469+
470+
/**
471+
* Gets the public 'mailer.transport_factory.amazon' shared service.
472+
*
473+
* @return \stdClass
474+
*/
475+
protected function getMailer_TransportFactory_AmazonService()
476+
{
477+
$a = ($this->services['monolog.logger_2'] ?? $this->getMonolog_Logger2Service());
478+
479+
if (isset($this->services['mailer.transport_factory.amazon'])) {
480+
return $this->services['mailer.transport_factory.amazon'];
481+
}
482+
483+
return $this->services['mailer.transport_factory.amazon'] = new \stdClass($a);
484+
}
485+
437486
/**
438487
* Gets the public 'manager' shared service.
439488
*
@@ -482,6 +531,34 @@ protected function getManager3Service($lazyLoad = true)
482531
return $this->services['manager3'] = new \stdClass($a);
483532
}
484533

534+
/**
535+
* Gets the public 'monolog.logger' shared service.
536+
*
537+
* @return \stdClass
538+
*/
539+
protected function getMonolog_LoggerService()
540+
{
541+
$this->services['monolog.logger'] = $instance = new \stdClass();
542+
543+
$instance->handler = ($this->services['mailer.transport'] ?? $this->getMailer_TransportService());
544+
545+
return $instance;
546+
}
547+
548+
/**
549+
* Gets the public 'monolog.logger_2' shared service.
550+
*
551+
* @return \stdClass
552+
*/
553+
protected function getMonolog_Logger2Service()
554+
{
555+
$this->services['monolog.logger_2'] = $instance = new \stdClass();
556+
557+
$instance->handler = ($this->services['mailer.transport'] ?? $this->getMailer_TransportService());
558+
559+
return $instance;
560+
}
561+
485562
/**
486563
* Gets the public 'root' shared service.
487564
*

0 commit comments

Comments
 (0)