8000 [DI] configure inlined services before injecting when dumping the con… · symfony/symfony@ae193cd · GitHub
[go: up one dir, main page]

Skip to content

Commit ae193cd

Browse files
[DI] configure inlined services before injecting when dumping the container
1 parent 432487f commit ae193cd

11 files changed

+192
-287
lines changed

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

Lines changed: 140 additions & 262 deletions
Large diffs are not rendered by default.

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,14 @@ public function testDeepServiceGraph()
890890
$dumper = new PhpDumper($container);
891891
$dumper->dump();
892892

893-
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump());
893+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Deep_Graph')));
894+
895+
require self::$fixturesPath.'/php/services_deep_graph.php';
896+
897+
$container = new \Symfony_DI_PhpDumper_Test_Deep_Graph();
898+
899+
$this->assertInstanceOf(FooForDeepGraph::class, $container->get('foo'));
900+
$this->assertEquals((object) array('p2' => (object) array('p3' => (object) array())), $container->get('foo')->bClone);
894901
}
895902

896903
public function testHotPathOptimizations()
@@ -1041,3 +1048,14 @@ public static function getProvidedTypes()
10411048
return array('rot13' => 'string');
10421049
}
10431050
}
1051+
1052+
class FooForDeepGraph
1053+
{
1054+
public $bClone;
1055+
1056+
public function __construct(\stdClass $a, \stdClass $b)
1057+
{
1058+
// clone to verify that $b has been fully initialized before
1059+
$this->bClone = clone $b;
1060+
}
1061+
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services13.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function getRemovedIds()
6767
protected function getBarService()
6868
{
6969
$a = new \stdClass();
70+
7071
$a->add($this);
7172

7273
return $this->services['bar'] = new \stdClass($a);

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
7575
$this->services['configured_service'] = $instance = new \stdClass();
7676

7777
$a = new \ConfClass();
78+
7879
$a->setFoo(($this->services['baz'] ?? $this->load('getBazService.php')));
7980

8081
$a->configureStdClass($instance);
@@ -294,6 +295,7 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
294295
// Returns the public 'new_factory_service' shared service.
295296

296297
$a = new \FactoryClass();
298+
297299
$a->foo = 'bar';
298300

299301
$this->services['new_factory_service'] = $instance = $a->getInstance();

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ protected function getConfiguredServiceService()
171171
$this->services['configured_service'] = $instance = new \stdClass();
172172

173173
$a = new \ConfClass();
174+
174175
$a->setFoo(($this->services['baz'] ?? $this->getBazService()));
175176

176177
$a->configureStdClass($instance);
@@ -365,6 +366,7 @@ protected function getMethodCall1Service()
365366
protected function getNewFactoryServiceService()
366367
{
367368
$a = new \FactoryClass();
369+
368370
$a->foo = 'bar';
369371

370372
$this->services['new_factory_service'] = $instance = $a->getInstance();

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_private.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ protected function getConnectionService()
125125
$this->services['connection'] = $instance = new \stdClass($a, $b);
126126

127127
$a->subscriber = ($this->services['subscriber'] ?? $this->getSubscriberService());
128+
128129
$b->logger = ($this->services['logger'] ?? $this->getLoggerService());
129130

130131
return $instance;
@@ -139,17 +140,19 @@ protected function getConnection2Service()
139140
{
140141
$a = new \stdClass();
141142

142-
$b = new \stdClass();
143+
$c = new \stdClass();
143144

144-
$this->services['connection2'] = $instance = new \stdClass($a, $b);
145+
$this->services['connection2'] = $instance = new \stdClass($a, $c);
145146

146-
$c = ($this->services['manager2'] ?? $this->getManager2Service());
147+
$b = ($this->services['manager2'] ?? $this->getManager2Service());
148+
149+
$a->subscriber2 = new \stdClass($b);
147150

148151
$d = new \stdClass($instance);
149152

150-
$a->subscriber2 = new \stdClass($c);
151-
$d->handler2 = new \stdClass($c);
152-
$b->logger2 = $d;
153+
$d->handler2 = new \stdClass($b);
154+
155+
$c->logger2 = $d;
153156

154157
return $instance;
155158
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_almost_circular_public.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ protected function getConnection2Service()
173173
$c = new \stdClass($instance);
174174

175175
$c->handler2 = new \stdClass(($this->services['manager2'] ?? $this->getManager2Service()));
176+
176177
$b->logger2 = $c;
177178

178179
return $instance;

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_deep_graph.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @final since Symfony 3.3
1616
*/
17-
class ProjectServiceContainer extends Container
17+
class Symfony_DI_PhpDumper_Test_Deep_Graph extends Container
1818
{
1919
private $parameters;
2020
private $targetDirs = array();
@@ -62,21 +62,21 @@ public function getRemovedIds()
6262
/**
6363
* Gets the public 'bar' shared service.
6464
*
65-
* @return \c5
65+
* @return \stdClass
6666
*/
6767
protected function getBarService()
6868
{
69-
$this->services['bar'] = $instance = new \c5();
69+
$this->services['bar'] = $instance = new \stdClass();
7070

71-
$instance->p5 = new \c6(($this->services['foo'] ?? $this->getFooService()));
71+
$instance->p5 = new \stdClass(($this->services['foo'] ?? $this->getFooService()));
7272

7373
return $instance;
7474
}
7575

7676
/**
7777
* Gets the public 'foo' shared service.
7878
*
79-
* @return \c1
79+
* @return \Symfony\Component\DependencyInjection\Tests\Dumper\FooForDeepGraph
8080
*/
8181
protected function getFooService()
8282
{
@@ -86,15 +86,13 @@ protected function getFooService()
8686
return $this->services['foo'];
8787
}
8888

89-
$b = new \c2();
89+
$b = new \stdClass();
9090

91-
$this->services['foo'] = $instance = new \c1($a, $b);
91+
$c = new \stdClass();
9292

93-
$c = new \c3();
94-
95-
$c->p3 = new \c4();
93+
$c->p3 = new \stdClass();
9694
$b->p2 = $c;
9795

98-
return $instance;
96+
return $this->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\FooForDeepGraph($a, $b);
9997
}
10098
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_errored_definition.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ protected function getConfiguredServiceService()
171171
$this->services['configured_service'] = $instance = new \stdClass();
172172

173173
$a = new \ConfClass();
174+
174175
$a->setFoo(($this->services['baz'] ?? $this->getBazService()));
175176

176177
$a->configureStdClass($instance);
@@ -365,6 +366,7 @@ protected function getMethodCall1Service()
365366
protected function getNewFactoryServiceService()
366367
{
367368
$a = new \FactoryClass();
369+
368370
$a->foo = 'bar';
369371

370372
$this->services['new_factory_service'] = $instance = $a->getInstance();

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services_inline_requires.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ protected function getC1Service()
101101
*/
102102
protected function getC2Service()
103103
{
104-
include_once $this->targetDirs[1].'/includes/HotPath/C3.php';
105104
include_once $this->targetDirs[1].'/includes/HotPath/C2.php';
105+
include_once $this->targetDirs[1].'/includes/HotPath/C3.php';
106106

107107
return $this->services['Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2'] = new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C2(new \Symfony\Component\DependencyInjection\Tests\Fixtures\includes\HotPath\C3());
108108
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11

22
services:
33
foo:
4-
class: c1
4+
class: Symfony\Component\DependencyInjection\Tests\Dumper\FooForDeepGraph
55
public: true
66
arguments:
77
- '@bar'
88
- !service
9-
class: c2
9+
class: stdClass
1010
properties:
1111
p2: !service
12-
class: c3
12+
class: stdClass
1313
properties:
1414
p3: !service
15-
class: c4
15+
class: stdClass
1616

1717
bar:
18-
class: c5
18+
class: stdClass
1919
public: true
2020
properties:
2121
p5: !service
22-
class: c6
22+
class: stdClass
2323
arguments: ['@foo']
2424

0 commit comments

Comments
 (0)
0