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 df44236

Browse filesBrowse files
bug #27688 [DI] fix dumping errored definitions (nicolas-grekas)
This PR was merged into the 4.2-dev branch. Discussion ---------- [DI] fix dumping errored definitions | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Removes dead code and correctly adds the "throw()" method at class' end. Commits ------- 6285e68 [DI] fix dumping errored definitions
2 parents 72bf72a + 6285e68 commit df44236
Copy full SHA for df44236

File tree

Expand file treeCollapse file tree

3 files changed

+25
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-9
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
+3-9Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ public function dump(array $options = array())
186186
$code =
187187
$this->startClass($options['class'], $baseClass, $baseClassWithNamespace).
188188
$this->addServices().
189-
$this->addDefaultParametersMethod().
190-
$this->endClass()
189+
$this->addDefaultParametersMethod()
191190
;
192191

193192
if ($this->asFiles) {
@@ -223,7 +222,7 @@ public function dump(array $options = array())
223222
foreach ($this->generateProxyClasses() as $file => $c) {
224223
$files[$file] = "<?php\n".$c;
225224
}
226-
$files[$options['class'].'.php'] = $code;
225+
$files[$options['class'].'.php'] = $code.$this->endClass();
227226
$hash = ucfirst(strtr(ContainerBuilder::hash($files), '._', 'xx'));
228227
$code = array();
229228

@@ -261,6 +260,7 @@ public function dump(array $options = array())
261260
262261
EOF;
263262
} else {
263+
$code .= $this->endClass();
264264
foreach ($this->generateProxyClasses() as $c) {
265265
$code .= $c;
266266
}
@@ -755,12 +755,6 @@ protected function {$methodName}($lazyInitialization)
755755
EOF;
756756
}
757757

758-
if ($e = $definition->getErrors()) {
759-
$e = sprintf("throw new RuntimeException(%s);\n", $this->export(reset($e)));
760-
761-
return $asFile ? substr($code, 8).$e : $code.' '.$e." }\n";
762-
}
763-
764758
$inlinedDefinitions = $this->getDefinitionsFromArguments(array($definition));
765759
$constructorDefinitions = $this->getDefinitionsFromArguments(array($definition->getArguments(), $definition->getFactory()));
766760
$otherDefinitions = new \SplObjectStorage();

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ public function testDumpAsFiles()
213213
->setFile(realpath(self::$fixturesPath.'/includes/foo.php'))
214214
->setShared(false)
215215
->setPublic(true);
216+
$container->register('throwing_one', \Bar\FooClass::class)
217+
->addArgument(new Reference('errored_one', ContainerBuilder::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE))
218+
->setPublic(true);
219+
$container->register('errored_one', 'stdClass')
220+
->addError('No-no-no-no');
216221
$container->compile();
217222
$dumper = new PhpDumper($container);
218223
$dump = print_r($dumper->dump(array('as_files' => true, 'file' => __DIR__, 'hot_path_tag' => 'hot')), true);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ return array(
1010
'decorated.pif-pouf' => true,
1111
'decorator_service.inner' => true,
1212
'errored_definition' => true,
13+
'errored_one' => true,
1314
'factory_simple' => true,
1415
'inlined' => true,
1516
'new_factory' => true,
@@ -341,6 +342,16 @@ return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(fun
341342
yield 1 => ($this->privates['tagged_iterator_foo'] ?? $this->privates['tagged_iterator_foo'] = new \Bar());
342343
}, 2));
343344

345+
[Container%s/getThrowingOneService.php] => <?php
346+
347+
use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
348+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
349+
350+
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
351+
// Returns the public 'throwing_one' shared service.
352+
353+
return $this->services['throwing_one'] = new \Bar\FooClass($this->throw('No-no-no-no'));
354+
344355
[Container%s/ProjectServiceContainer.php] => <?php
345356

346357
namespace Container%s;
@@ -412,6 +423,7 @@ class ProjectServiceContainer extends Container
412423
'runtime_error' => 'getRuntimeErrorService.php',
413424
'service_from_static_method' => 'getServiceFromStaticMethodService.php',
414425
'tagged_iterator' => 'getTaggedIteratorService.php',
426+
'throwing_one' => 'getThrowingOneService.php',
415427
);
416428
$this->aliases = array(
417429
'alias_for_alias' => 'foo',
@@ -540,6 +552,11 @@ class ProjectServiceContainer extends Container
540552
'foo' => 'bar',
541553
);
542554
}
555+
556+
protected function throw($message)
557+
{
558+
throw new RuntimeException($message);
559+
}
543560
}
544561

545562
[ProjectServiceContainer.php] => <?php

0 commit comments

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