Skip to content

Commit ef44ed4

Browse files
Merge branch '3.4' into 4.1
* 3.4: [DI] configure inlined services before injecting them when dumping the container Consistently throw exceptions on a single line fix fopen calls Update .editorconfig
2 parents e8d529b + 0c65764 commit ef44ed4

11 files changed

+189
-316
lines changed

Compiler/CheckDefinitionValidityPass.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,7 @@ public function process(ContainerBuilder $container)
6666
));
6767
}
6868

69-
throw new RuntimeException(sprintf(
70-
'The definition for "%s" has no class. If you intend to inject '
71-
.'this service dynamically at runtime, please mark it as synthetic=true. '
72-
.'If this is an abstract definition solely used by child definitions, '
73-
.'please add abstract=true, otherwise specify a class to get rid of this error.',
74-
$id
75-
));
69+
throw new RuntimeException(sprintf('The definition for "%s" has no class. If you intend to inject this service dynamically at runtime, please mark it as synthetic=true. If this is an abstract definition solely used by child definitions, please add abstract=true, otherwise specify a class to get rid of this error.', $id));
7670
}
7771

7872
// tag attribute values must be scalars

Compiler/CheckReferenceValidityPass.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ protected function processValue($value, $isRoot = false)
3434
$targetDefinition = $this->container->getDefinition((string) $value);
3535

3636
if ($targetDefinition->isAbstract()) {
37-
throw new RuntimeException(sprintf(
38-
'The definition "%s" has a reference to an abstract definition "%s". '
39-
.'Abstract definitions cannot be the target of references.',
40-
$this->currentId,
41-
$value
42-
));
37+
throw new RuntimeException(sprintf('The definition "%s" has a reference to an abstract definition "%s". Abstract definitions cannot be the target of references.', $this->currentId, $value));
4338
}
4439
}
4540

Dumper/PhpDumper.php

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

Loader/XmlFileLoader.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -669,13 +669,7 @@ private function validateExtensions(\DOMDocument $dom, $file)
669669
// can it be handled by an extension?
670670
if (!$this->container->hasExtension($node->namespaceURI)) {
671671
$extensionNamespaces = array_filter(array_map(function (ExtensionInterface $ext) { return $ext->getNamespace(); }, $this->container->getExtensions()));
672-
throw new InvalidArgumentException(sprintf(
673-
'There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s',
674-
$node->tagName,
675-
$file,
676-
$node->namespaceURI,
677-
$extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'
678-
));
672+
throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s', $node->tagName, $file, $node->namespaceURI, $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'));
679673
}
680674
}
681675
}

Loader/YamlFileLoader.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -654,13 +654,7 @@ private function validate($content, $file)
654654

655655
if (!$this->container->hasExtension($namespace)) {
656656
$extensionNamespaces = array_filter(array_map(function (ExtensionInterface $ext) { return $ext->getAlias(); }, $this->container->getExtensions()));
657-
throw new InvalidArgumentException(sprintf(
658-
'There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s',
659-
$namespace,
660-
$file,
661-
$namespace,
662-
$extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'
663-
));
657+
throw new InvalidArgumentException(sprintf('There is no extension able to load the configuration for "%s" (in %s). Looked for namespace "%s", found %s', $namespace, $file, $namespace, $extensionNamespaces ? sprintf('"%s"', implode('", "', $extensionNamespaces)) : 'none'));
664658
}
665659
}
666660

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+
}

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
}

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;

Tests/Fixtures/php/services_deep_graph.php

Lines changed: 9 additions & 13 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,11 @@ protected function getFooService()
8686
return $this->services['foo'];
8787
}
8888

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();
89+
$b = new \stdClass();
90+
$c = new \stdClass();
91+
$c->p3 = new \stdClass();
9692
$b->p2 = $c;
9793

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

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
}

0 commit comments

Comments
 (0)