8000 [DI] fix error in dumped container · symfony/symfony@2d0aba6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d0aba6

Browse files
[DI] fix error in dumped container
1 parent 00efcd4 commit 2d0aba6

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ private function addInlineReference(&$head, &$tail, $id, $targetId, $forConstruc
751751

752752
EOTXT
753753
,
754-
$this->container->getDefinition($id)->isPublic() ? 'services' : 'privates',
754+
'services',
755755
$id
756756
);
757757

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

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

13861386
$manager = $container->get('manager2');
13871387
$this->assertEquals(new \stdClass(), $manager);
1388+
1389+
$foo6 = $container->get('foo6');
1390+
$this->assertEquals((object) array('bar6' => (object) array()), $foo6);
13881391
}
13891392

13901393
public function provideAlmostCircular()

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

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

831831
$manager = $container->get('manager2');
832832
$this->assertEquals(new \stdClass(), $manager);
833+
834+
$foo6 = $container->get('foo6');
835+
$this->assertEquals((object) array('bar6' => (object) array()), $foo6);
833836
}
834837

835838
public function provideAlmostCircular()

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,18 @@
101101
$container->register('subscriber2', 'stdClass')->setPublic(false)
102102
->addArgument(new Reference('manager2'));
103103

104+
// private service involved in a loop
105+
106+
$container->register('foo6', 'stdClass')
107+
->setPublic(true)
108+
->setProperty('bar6', new Reference('bar6'));
109+
110+
$container->register('bar6', 'stdClass')
111+
->setPublic(false)
112+
->addArgument(new Reference('foo6'));
113+
114+
$container->register('baz6', 'stdClass')
115+
->setPublic(true)
116+
->setProperty('bar6', new Reference('bar6'));
117+
104118
return $container;

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,23 @@ public function __construct()
2525
$this->methodMap = array(
2626
'bar2' => 'getBar2Service',
2727
'bar3' => 'getBar3Service',
28+
'bar6' => 'getBar6Service',
29+
'baz6' => 'getBaz6Service',
2830
'connection' => 'getConnectionService',
2931
'connection2' => 'getConnection2Service',
3032
'foo' => 'getFooService',
3133
'foo2' => 'getFoo2Service',
3234
'foo5' => 'getFoo5Service',
35+
'foo6' => 'getFoo6Service',
3336
'foobar4' => 'getFoobar4Service',
3437
'logger' => 'getLoggerService',
3538
'manager' => 'getManagerService',
3639
'manager2' => 'getManager2Service',
3740
'subscriber' => 'getSubscriberService',
3841
);
42+
$this->privates = array(
43+
'bar6' => true,
44+
);
3945

4046
$this->aliases = array();
4147
}
@@ -47,6 +53,7 @@ public function getRemovedIds()
4753
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
4854
'bar' => true,
4955
'bar5' => true,
56+
'bar6' => true,
5057
'config' => true,
5158
'config2' => true,
5259
'dispatcher' => true,
@@ -107,6 +114,20 @@ protected function getBar3Service()
107114
return $instance;
108115
}
109116

117+
/**
118+
* Gets the public 'baz6' shared service.
119+
*
120+
* @return \stdClass
121+
*/
122+
protected function getBaz6Service()
123+
{
124+
$this->services['baz6'] = $instance = new \stdClass();
125+
126+
$instance->bar6 = ${($_ = isset($this->services['bar6']) ? $this->services['bar6'] : $this->getBar6Service()) && false ?: '_'};
127+
128+
return $instance;
129+
}
130+
110131
/**
111132
* Gets the public 'connection' shared service.
112133
*
@@ -203,6 +224,20 @@ protected function getFoo5Service()
203224
return $instance;
204225
}
205226

227+
/**
228+
* Gets the public 'foo6' shared service.
229+
*
230+
* @return \stdClass
231+
*/
232+
protected function getFoo6Service()
233+
{
234+
$this->services['foo6'] = $instance = new \stdClass();
235+
236+
$instance->bar6 = ${($_ = isset($this->services['bar6']) ? $this->services['bar6'] : $this->getBar6Service()) && false ?: '_'};
237+
238+
return $instance;
239+
}
240+
206241
/**
207242
* Gets the public 'foobar4' shared service.
208243
*
@@ -286,4 +321,20 @@ protected function getSubscriberService()
286321

287322
return $this->services['subscriber'] = new \stdClass($a);
288323
}
324+
325+
/**
326+
* Gets the private 'bar6' shared service.
327+
*
328+
* @return \stdClass
329+
*/
330+
protected function getBar6Service()
331+
{
332+
$a = ${($_ = isset($this->services['foo6']) ? $this->services['foo6'] : $this->getFoo6Service()) && false ?: '_'};
333+
334+
if (isset($this->services['bar6'])) {
335+
return $this->services['bar6'];
336+
}
337+
338+
return $this->services['bar6'] = new \stdClass($a);
339+
}
289340
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function __construct()
2626
'bar' => 'getBarService',
2727
'bar3' => 'getBar3Service',
2828
'bar5' => 'getBar5Service',
29+
'bar6' => 'getBar6Service',
30+
'baz6' => 'getBaz6Service',
2931
'connection' => 'getConnectionService',
3032
'connection2' => 'getConnection2Service',
3133
'dispatcher' => 'getDispatcherService',
@@ -34,6 +36,7 @@ public function __construct()
3436
'foo2' => 'getFoo2Service',
3537
'foo4' => 'getFoo4Service',
3638
'foo5' => 'getFoo5Service',
39+
'foo6' => 'getFoo6Service',
3740
'foobar' => 'getFoobarService',
3841
'foobar2' => 'getFoobar2Service',
3942
'foobar3' => 'getFoobar3Service',
@@ -43,6 +46,9 @@ public function __construct()
4346
'manager2' => 'getManager2Service',
4447
'subscriber' => 'getSubscriberService',
4548
);
49+
$this->privates = array(
50+
'bar6' => true,
51+
);
4652

4753
$this->aliases = array();
4854
}
@@ -53,6 +59,7 @@ public function getRemovedIds()
5359
'Psr\\Container\\ContainerInterface' => true,
5460< F438 /code>
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
5561
'bar2' => true,
62+
'bar6' => true,
5663
'config' => true,
5764
'config2' => true,
5865
'logger2' => true,
@@ -127,6 +134,20 @@ protected function getBar5Service()
127134
return $instance;
128135
}
129136

137+
/**
138+
* Gets the public 'baz6' shared service.
139+
*
140+
* @return \stdClass
141+
*/
142+
protected function getBaz6Service()
143+
{
144+
$this->services['baz6'] = $instance = new \stdClass();
145+
146+
$instance->bar6 = ${($_ = isset($this->services['bar6']) ? $this->services['bar6'] : $this->getBar6Service()) && false ?: '_'};
147+
148+
return $instance;
149+
}
150+
130151
/**
131152
* Gets the public 'connection' shared service.
132153
*
@@ -251,6 +272,20 @@ protected function getFoo5Service()
251272
return $instance;
252273
}
253274

275+
/**
276+
* Gets the public 'foo6' shared service.
277+
*
278+
* @return \stdClass
279+
*/
280+
protected function getFoo6Service()
281+
{
282+
$this->services['foo6'] = $instance = new \stdClass();
283+
284+
$instance->bar6 = ${($_ = isset($this->services['bar6']) ? $this->services['bar6'] : $this->getBar6Service()) && false ?: '_'};
285+
286+
return $instance;
287+
}
288+
254289
/**
255290
* Gets the public 'foobar' shared service.
256291
*
@@ -370,4 +405,20 @@ protected function getSubscriberService()
370405
{
371406
return $this->services['subscriber'] = new \stdClass(${($_ = isset($this->services['manager']) ? $this->services['manager'] : $this->getManagerService()) && false ?: '_'});
372407
}
408+
409+
/**
410+
* Gets the private 'bar6' shared service.
411+
*
412+
* @return \stdClass
413+
*/
414+
protected function getBar6Service()
415+
{
416+
$a = ${($_ = isset($this->services['foo6']) ? $this->services['foo6'] : $this->getFoo6Service()) && false ?: '_'};
417+
418+
if (isset($this->services['bar6'])) {
419+
return $this->services['bar6'];
420+
}
421+
422+
return $this->services['bar6'] = new \stdClass($a);
423+
}
373424
}

0 commit comments

Comments
 (0)
0