8000 [DI] fix dumping errored definitions · symfony/symfony@6285e68 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6285e68

Browse files
[DI] fix dumping errored definitions
1 parent 72bf72a commit 6285e68

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

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

Lines 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

Lines 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

Lines 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