Skip to content

Commit 1c5eeb5

Browse files
Merge branch '3.4'
* 3.4: Remove useless phpdoc [DI] Fix the "almost-circular refs" fix [Form] Fix low deps
2 parents 145587c + e7cfaa9 commit 1c5eeb5

File tree

7 files changed

+168
-35
lines changed

7 files changed

+168
-35
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,29 +1400,37 @@ private function hasReference($id, array $arguments, $deep = false, array &$visi
14001400
if ($this->hasReference($id, $argument, $deep, $visited)) {
14011401
return true;
14021402
}
1403+
1404+
continue;
14031405
} elseif ($argument instanceof Reference) {
14041406
$argumentId = (string) $argument;
14051407
if ($id === $argumentId) {
14061408
return true;
14071409
}
14081410

1409-
if ($deep && !isset($visited[$argumentId]) && 'service_container' !== $argumentId) {
1410-
$visited[$argumentId] = true;
1411+
if (!$deep || isset($visited[$argumentId]) || 'service_container' === $argumentId) {
1412+
continue;
1413+
}
14111414

1412-
$service = $this->container->getDefinition($argumentId);
1415+
$visited[$argumentId] = true;
14131416

1414-
// if the proxy manager is enabled, disable searching for references in lazy services,
1415-
// as these services will be instantiated lazily and don't have direct related references.
1416-
if ($service->isLazy() && !$this->getProxyDumper() instanceof NullDumper) {
1417-
continue;
1418-
}
1417+
$service = $this->container->getDefinition($argumentId);
1418+
} elseif ($argument instanceof Definition) {
1419+
$service = $argument;
1420+
} else {
1421+
continue;
1422+
}
14191423

1420-
$arguments = array_merge($service->getMethodCalls(), $service->getArguments(), $service->getProperties());
1424+
// if the proxy manager is enabled, disable searching for references in lazy services,
1425+
// as these services will be instantiated lazily and don't have direct related references.
1426+
if ($service->isLazy() && !$this->getProxyDumper() instanceof NullDumper) {
1427+
continue;
1428+
}
14211429

1422-
if ($this->hasReference($id, $arguments, $deep, $visited)) {
1423-
return true;
1424-
}
1425-
}
1430+
$arguments = array_merge($service->getMethodCalls(), $service->getArguments(), $service->getProperties());
1431+
1432+
if ($this->hasReference($id, $arguments, $deep, $visited)) {
1433+
return true;
14261434
}
14271435
}
14281436

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,19 @@ public function testUninitializedReference()
11771177
$this->assertEquals(array('foo1' => new \stdClass(), 'foo3' => new \stdClass()), iterator_to_array($bar->iter));
11781178
}
11791179

1180-
public function testAlmostCircular()
1180+
public function testAlmostCircularPrivate()
11811181
{
1182+
$public = false;
1183+
$container = include __DIR__.'/Fixtures/containers/container_almost_circular.php';
1184+
1185+
$foo = $container->get('foo');
1186+
1187+
$this->assertSame($foo, $foo->bar->foobar->foo);
1188+
}
1189+
1190+
public function testAlmostCircularPublic()
1191+
{
1192+
$public = true;
11821193
$container = include __DIR__.'/Fixtures/containers/container_almost_circular.php';
11831194

11841195
$foo = $container->get('foo');

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,17 +763,35 @@ public function testUninitializedReference()
763763
$this->assertEquals(array('foo1' => new \stdClass(), 'foo3' => new \stdClass()), iterator_to_array($bar->iter));
764764
}
765765

766-
public function xtestAlmostCircular()
766+
public function testAlmostCircularPrivate()
767767
{
768+
$public = false;
768769
$container = include self::$fixturesPath.'/containers/container_almost_circular.php';
769770
$container->compile();
770771
$dumper = new PhpDumper($container);
771772

772-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/container_almost_circular.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Almost_Circular')));
773+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/container_almost_circular_private.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Almost_Circular_Private')));
773774

774-
require self::$fixturesPath.'/php/container_almost_circular.php';
775+
require self::$fixturesPath.'/php/container_almost_circular_private.php';
775776

776-
$container = new \Symfony_DI_PhpDumper_Test_Almost_Circular();
777+
$container = new \Symfony_DI_PhpDumper_Test_Almost_Circular_Private();
778+
$foo = $container->get('foo');
779+
780+
$this->assertSame($foo, $foo->bar->foobar->foo);
781+
}
782+
783+
public function testAlmostCircularPublic()
784+
{
785+
$public = true;
786+
$container = include self::$fixturesPath.'/containers/container_almost_circular.php';
787+
$container->compile();
788+
$dumper = new PhpDumper($container);
789+
790+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/container_almost_circular_public.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Almost_Circular_Public')));
791+
792+
require self::$fixturesPath.'/php/container_almost_circular_public.php';
793+
794+
$container = new \Symfony_DI_PhpDumper_Test_Almost_Circular_Public();
777795
$foo = $container->get('foo');
778796

779797
$this->assertSame($foo, $foo->bar->foobar->foo);

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_almost_circular.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
$container->register('foo', FooCircular::class)->setPublic(true)
1111
->addArgument(new Reference('bar'));
1212

13-
$container->register('bar', BarCircular::class)
13+
$container->register('bar', BarCircular::class)->setPublic($public)
1414
->addMethodCall('addFoobar', array(new Reference('foobar')));
1515

16-
$container->register('foobar', FoobarCircular::class)
16+
$container->register('foobar', FoobarCircular::class)->setPublic($public)
1717
->addArgument(new Reference('foo'));
1818

1919
return $container;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/container_almost_circular.php renamed to src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/container_almost_circular_private.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @final since Symfony 3.3
1616
*/
17-
class Symfony_DI_PhpDumper_Test_Almost_Circular extends Container
17+
class Symfony_DI_PhpDumper_Test_Almost_Circular_Private extends Container
1818
{
1919
private $parameters;
2020
private $targetDirs = array();
@@ -64,8 +64,12 @@ public function getRemovedIds()
6464
protected function getFooService()
6565
{
6666
$a = new \BarCircular();
67-
$a->addFoobar(new \FoobarCircular(($this->services['foo'] ?? $this->getFooService())));
6867

69-
return $this->services['foo'] = new \FooCircular($a);
68+
$this->services['foo'] = $instance = new \FooCircular($a);
69+
70+
$a->addFoobar(new \FoobarCircular($instance));
71+
72+
73+
return $instance;
7074
}
7175
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
4+
use Symfony\Component\DependencyInjection\ContainerInterface;
5+
use Symfony\Component\DependencyInjection\Container;
6+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7+
use Symfony\Component\DependencyInjection\Exception\LogicException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
11+
/**
12+
* This class has been auto-generated
13+
* by the Symfony Dependency Injection Component.
14+
*
15+
* @final since Symfony 3.3
16+
*/
17+
class Symfony_DI_PhpDumper_Test_Almost_Circular_Public extends Container
18+
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
private $privates = array();
22+
23+
public function __construct()
24+
{
25+
$this->services = $this->privates = array();
26+
$this->methodMap = array(
27+
'bar' => 'getBarService',
28+
'foo' => 'getFooService',
29+
'foobar' => 'getFoobarService',
30+
);
31+
32+
$this->aliases = array();
33+
}
34+
35+
public function reset()
36+
{
37+
$this->privates = array();
38+
parent::reset();
39+
}
40+
41+
public function compile()
42+
{
43+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
44+
}
45+
46+
public function isCompiled()
47+
{
48+
return true;
49+
}
50+
51+
public function getRemovedIds()
52+
{
53+
return array(
54+
'Psr\\Container\\ContainerInterface' => true,
55+
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
56+
);
57+
}
58+
59+
/**
60+
* Gets the public 'bar' shared service.
61+
*
62+
* @return \BarCircular
63+
*/
64+
protected function getBarService()
65+
{
66+
$this->services['bar'] = $instance = new \BarCircular();
67+
68+
$instance->addFoobar(($this->services['foobar'] ?? $this->getFoobarService()));
69+
70+
return $instance;
71+
}
72+
73+
/**
74+
* Gets the public 'foo' shared service.
75+
*
76+
* @return \FooCircular
77+
*/
78+
protected function getFooService()
79+
{
80+
$a = ($this->services['bar'] ?? $this->getBarService());
81+
82+
if (isset($this->services['foo'])) {
83+
return $this->services['foo'];
84+
}
85+
86+
return $this->services['foo'] = new \FooCircular($a);
87+
}
88+
89+
/**
90+
* Gets the public 'foobar' shared service.
91+
*
92+
* @return \FoobarCircular
93+
*/
94+
protected function getFoobarService()
95+
{
96+
$a = ($this->services['foo'] ?? $this->getFooService());
97+
98+
if (isset($this->services['foobar'])) {
99+
return $this->services['foobar'];
100+
}
101+
102+
return $this->services['foobar'] = new \FoobarCircular($a);
103+
}
104+
}

src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,8 @@ class PhpDocExtractor implements PropertyDescriptionExtractorInterface, Property
4141
private $docBlockFactory;
4242
private $contextFactory;
4343
private $phpDocTypeHelper;
44-
45-
/**
46-
* @var string[]
47-
*/
4844
private $mutatorPrefixes;
49-
50-
/**
51-
* @var string[]
52-
*/
5345
private $accessorPrefixes;
54-
55-
/**
56-
* @var string[]
57-
*/
5846
private $arrayMutatorPrefixes;
5947

6048
/**

0 commit comments

Comments
 (0)