Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cba6421

Browse filesBrowse files
Merge branch '3.4' into 4.1
* 3.4: [DI] Fix dumping some complex service graphs change baseUrl to basePath to fix wrong profiler url
2 parents 150bd84 + 8851c14 commit cba6421
Copy full SHA for cba6421

File tree

9 files changed

+161
-16
lines changed
Filter options

9 files changed

+161
-16
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
+12-5Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ private function addServiceInlinedDefinitions(string $id, Definition $definition
511511

512512
$code .= $this->addNewInstance($def, '$'.$name, ' = ', $id);
513513

514-
if (!$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true)) {
514+
if (!$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true, $inlinedDefinitions)) {
515515
$code .= $this->addServiceProperties($def, $name);
516516
$code .= $this->addServiceMethodCalls($def, $name);
517517
$code .= $this->addServiceConfigurator($def, $name);
@@ -637,7 +637,7 @@ private function addServiceInlinedDefinitionsSetup(string $id, Definition $defin
637637
{
638638
$code = '';
639639
foreach ($inlinedDefinitions as $def) {
640-
if ($definition === $def || !$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true)) {
640+
if ($definition === $def || !$this->hasReference($id, array($def->getProperties(), $def->getMethodCalls(), $def->getConfigurator()), true, $inlinedDefinitions)) {
641641
continue;
642642
}
643643

@@ -760,6 +760,7 @@ protected function {$methodName}($lazyInitialization)
760760

761761
$inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition));
762762
$constructorDefinitions = $this->getDefinitionsFromArguments(array($definition->getArguments(), $definition->getFactory()));
763+
unset($constructorDefinitions[$definition]); // ensures $definition will be last
763764
$otherDefinitions = new \SplObjectStorage();
764765
$serviceCalls = array();
765766

@@ -1076,6 +1077,9 @@ private function addRemovedIds(): string
10761077
$ids = array_keys($ids);
10771078
sort($ids);
10781079
foreach ($ids as $id) {
1080+
if (preg_match('/^\.\d+_[^~]++~[._a-zA-Z\d]{7}$/', $id)) {
1081+
continue;
1082+
}
10791083
$code .= ' '.$this->doExport($id)." => true,\n";
10801084
}
10811085

@@ -1423,15 +1427,15 @@ private function getDefinitionsFromArguments(array $arguments, bool $isConstruct
14231427
return $definitions;
14241428
}
14251429

1426-
private function hasReference(string $id, array $arguments, bool $deep = false, array &$visited = array()): bool
1430+
private function hasReference(string $id, array $arguments, bool $deep = false, \SplObjectStorage $inlinedDefinitions = null, array &$visited = array()): bool
14271431
{
14281432
if (!isset($this->circularReferences[$id])) {
14291433
return false;
14301434
}
14311435

14321436
foreach ($arguments as $argument) {
14331437
if (\is_array($argument)) {
1434-
if ($this->hasReference($id, $argument, $deep, $visited)) {
1438+
if ($this->hasReference($id, $argument, $deep, $inlinedDefinitions, $visited)) {
14351439
return true;
14361440
}
14371441

@@ -1450,6 +1454,9 @@ private function hasReference(string $id, array $arguments, bool $deep = false,
14501454

14511455
$service = $this->container->getDefinition($argumentId);
14521456
} elseif ($argument instanceof Definition) {
1457+
if (isset($inlinedDefinitions[$argument])) {
1458+
return true;
1459+
}
14531460
$service = $argument;
14541461
} else {
14551462
continue;
@@ -1461,7 +1468,7 @@ private function hasReference(string $id, array $arguments, bool $deep = false,
14611468
continue;
14621469
}
14631470

1464-
if ($this->hasReference($id, array($service->getArguments(), $service->getFactory(), $service->getProperties(), $service->getMethodCalls(), $service->getConfigurator()), $deep, $visited)) {
1471+
if ($this->hasReference($id, array($service->getArguments(), $service->getFactory(), $service->getProperties(), $service->getMethodCalls(), $service->getConfigurator()), $deep, $inlinedDefinitions, $visited)) {
14651472
return true;
14661473
}
14671474
}

‎src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults)
399399
{
400400
$definitions = array();
401401
$count = 0;
402-
$suffix = ContainerBuilder::hash($file);
402+
$suffix = '~'.ContainerBuilder::hash($file);
403403

404404
$xpath = new \DOMXPath($xml);
405405
$xpath->registerNamespace('container', self::NS);
@@ -409,7 +409,7 @@ private function processAnonymousServices(\DOMDocument $xml, $file, $defaults)
409409
foreach ($nodes as $node) {
410410
if ($services = $this->getChildren($node, 'service')) {
411411
// give it a unique name
412-
$id = sprintf('.%d_%s', ++$count, preg_replace('/^.*\\\\/', '', $services[0]->getAttribute('class')).'~'.$suffix);
412+
$id = sprintf('.%d_%s', ++$count, preg_replace('/^.*\\\\/', '', $services[0]->getAttribute('class')).$suffix);
413413
$node->setAttribute('id', $id);
414414
$node->setAttribute('service', $id);
415415

‎src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function load($resource, $type = null)
142142

143143
// services
144144
$this->anonymousServicesCount = 0;
145-
$this->anonymousServicesSuffix = ContainerBuilder::hash($path);
145+
$this->anonymousServicesSuffix = '~'.ContainerBuilder::hash($path);
146146
$this->setCurrentDir(\dirname($path));
147147
try {
148148
$this->parseDefinitions($content, $path);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,21 @@ public function provideAlmostCircular()
878878
yield array('private');
879879
}
880880

881+
public function testDeepServiceGraph()
882+
{
883+
$container = new ContainerBuilder();
884+
885+
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
886+
$loader->load('services_deep_graph.yml');
887+
888+
$container->compile();
889+
890+
$dumper = new PhpDumper($container);
891+
$dumper->dump();
892+
893+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services_deep_graph.php', $dumper->dump());
894+
}
895+
881896
public function testHotPathOptimizations()
882897
{
883898
$container = include self::$fixturesPath.'/containers/container_inline_requires.php';
+100Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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 ProjectServiceContainer extends Container
18+
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
22+
/**
23+
* @internal but protected for BC on cache:clear
24+
*/
25+
protected $privates = array();
26+
27+
public function __construct()
28+
{
29+
$this->services = $this->privates = array();
30+
$this->methodMap = array(
31+
'bar' => 'getBarService',
32+
'foo' => 'getFooService',
33+
);
34+
35+
$this->aliases = array();
36+
}
37+
38+
public function reset()
39+
{
40+
$this->privates = array();
41+
parent::reset();
42+
}
43+
44+
public function compile()
45+
{
46+
throw new LogicException('You cannot compile a dumped container that was already compiled.');
47+
}
48+
49+
public function isCompiled()
50+
{
51+
return true;
52+
}
53+
54+
public function getRemovedIds()
55+
{
56+
return array(
57+
'Psr\\Container\\ContainerInterface' => true,
58+
'Symfony\\Component\\DependencyInjection\\ContainerInterface' => true,
59+
);
60+
}
61+
62+
/**
63+
* Gets the public 'bar' shared service.
64+
*
65+
* @return \c5
66+
*/
67+
protected function getBarService()
68+
{
69+
$this->services['bar'] = $instance = new \c5();
70+
71+
$instance->p5 = new \c6(($this->services['foo'] ?? $this->getFooService()));
72+
73+
return $instance;
74+
}
75+
76+
/**
77+
* Gets the public 'foo' shared service.
78+
*
79+
* @return \c1
80+
*/
81+
protected function getFooService()
82+
{
83+
$a = ($this->services['bar'] ?? $this->getBarService());
84+
85+
if (isset($this->services['foo'])) {
86+
return $this->services['foo'];
87+
}
88+
89+
$b = new \c2();
90+
91+
$this->services['foo'] = $instance = new \c1($a, $b);
92+
93+
$c = new \c3();
94+
95+
$c->p3 = new \c4();
96+
$b->p2 = $c;
97+
98+
return $instance;
99+
}
100+
}
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
services:
3+
foo:
4+
class: c1
5+
public: true
6+
arguments:
7+
- '@bar'
8+
- !service
9+
class: c2
10+
properties:
11+
p2: !service
12+
class: c3
13+
properties:
14+
p3: !service
15+
class: c4
16+
17+
bar:
18+
class: c5
19+
public: true
20+
properties:
21+
p5: !service
22+
class: c6
23+
arguments: ['@foo']
24+

‎src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ public function testAnonymousServices()
556556
$this->assertCount(1, $args);
557557
$this->assertInstanceOf(Reference::class, $args[0]);
558558
$this->assertTrue($container->has((string) $args[0]));
559-
$this->assertRegExp('/^\.\d+_Bar[._A-Za-z0-9]{7}$/', (string) $args[0]);
559+
$this->assertRegExp('/^\.\d+_Bar~[._A-Za-z0-9]{7}$/', (string) $args[0]);
560560

561561
$anonymous = $container->getDefinition((string) $args[0]);
562562
$this->assertEquals('Bar', $anonymous->getClass());
@@ -568,7 +568,7 @@ public function testAnonymousServices()
568568
$this->assertInternalType('array', $factory);
569569
$this->assertInstanceOf(Reference::class, $factory[0]);
570570
$this->assertTrue($container->has((string) $factory[0]));
571-
$this->assertRegExp('/^\.\d+_Quz[._A-Za-z0-9]{7}$/', (string) $factory[0]);
571+
$this->assertRegExp('/^\.\d+_Quz~[._A-Za-z0-9]{7}$/', (string) $factory[0]);
572572
$this->assertEquals('constructFoo', $factory[1]);
573573

574574
$anonymous = $container->getDefinition((string) $factory[0]);

‎src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Debug/FileLinkFormatter.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private function getFileLinkFormat()
9696
}
9797

9898
return array(
99-
$request->getSchemeAndHttpHost().$request->getBaseUrl().$this->urlFormat,
99+
$request->getSchemeAndHttpHost().$request->getBasePath().$this->urlFormat,
100100
$this->baseDir.\DIRECTORY_SEPARATOR, '',
101101
);
102102
}

‎src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/Debug/FileLinkFormatterTest.php
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function testWhenFileLinkFormatAndNoRequest()
3737
public function testWhenFileLinkFormatAndRequest()
3838
{
3939
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
40-
$baseDir = __DIR__;
4140
$requestStack = new RequestStack();
4241
$request = new Request();
4342
$requestStack->push($request);
@@ -56,12 +55,12 @@ public function testWhenNoFileLinkFormatAndRequest()
5655

5756
$request->server->set('SERVER_NAME', 'www.example.org');
5857
$request->server->set('SERVER_PORT', 80);
59-
$request->server->set('SCRIPT_NAME', '/app.php');
60-
$request->server->set('SCRIPT_FILENAME', '/web/app.php');
61-
$request->server->set('REQUEST_URI', '/app.php/example');
58+
$request->server->set('SCRIPT_NAME', '/index.php');
59+
$request->server->set('SCRIPT_FILENAME', '/public/index.php');
60+
$request->server->set('REQUEST_URI', '/index.php/example');
6261

6362
$sut = new FileLinkFormatter(null, $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
6463

65-
$this->assertSame('http://www.example.org/app.php/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
64+
$this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
6665
}
6766
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.