Skip to content

Commit a7908d7

Browse files
Merge branch '3.1'
* 3.1: `@throws` annotations should go after `@return` Fix merge updated VERSION for 2.3.42 update CONTRIBUTORS for 2.3.42 updated CHANGELOG for 2.3.42 Revert "bug #18908 [DependencyInjection] force enabling the external XML entity loaders (xabbuh)" Partial revert of previous PR [DependencyInjection] Skip deep reference check for 'service_container' Catch \Throwable [Serializer] Add missing @throws annotations Fix for #18843 force enabling the external XML entity loaders Removed UTC specification with timestamp
2 parents c091760 + 4ed3bcc commit a7908d7

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

Dumper/PhpDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ private function hasReference($id, array $arguments, $deep = false, array &$visi
11761176
return true;
11771177
}
11781178

1179-
if ($deep && !isset($visited[$argumentId])) {
1179+
if ($deep && !isset($visited[$argumentId]) && 'service_container' !== $argumentId) {
11801180
$visited[$argumentId] = true;
11811181

11821182
$service = $this->container->getDefinition($argumentId);

Tests/Dumper/PhpDumperTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,15 @@ public function testDumpAutowireData()
284284

285285
$this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services24.php'), $dumper->dump());
286286
}
287+
288+
public function testInlinedDefinitionReferencingServiceContainer()
289+
{
290+
$container = new ContainerBuilder();
291+
$container->register('foo', 'stdClass')->addMethodCall('add', array(new Reference('service_container')))->setPublic(false);
292+
$container->register('bar', 'stdClass')->addArgument(new Reference('foo'));
293+
$container->compile();
294+
295+
$dumper = new PhpDumper($container);
296+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
297+
}
287298
}

Tests/Fixtures/php/services13.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerInterface;
4+
use Symfony\Component\DependencyInjection\Container;
5+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
6+
use Symfony\Component\DependencyInjection\Exception\LogicException;
7+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
8+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
9+
10+
/**
11+
* ProjectServiceContainer.
12+
*
13+
* This class has been auto-generated
14+
* by the Symfony Dependency Injection Component.
15+
*/
16+
class ProjectServiceContainer extends Container
17+
{
18+
private $parameters;
19+
private $targetDirs = array();
20+
21+
/**
22+
* Constructor.
23+
*/
24+
public function __construct()
25+
{
26+
$this->services = array();
27+
$this->methodMap = array(
28+
'bar' => 'getBarService',
29+
);
30+
31+
$this->aliases = array();
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public function compile()
38+
{
39+
throw new LogicException('You cannot compile a dumped frozen container.');
40+
}
41+
42+
/**
43+
* Gets the 'bar' service.
44+
*
45+
* This service is shared.
46+
* This method always returns the same instance of the service.
47+
*
48+
* @return \stdClass A stdClass instance.
49+
*/
50+
protected function getBarService()
51+
{
52+
$a = new \stdClass();
53+
$a->add($this);
54+
55+
return $this->services['bar'] = new \stdClass($a);
56+
}
57+
}

0 commit comments

Comments
 (0)