Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit7c08e43

Browse files
committed
feature#28449 [DependencyInjection] improved message when alias service is not found (xabbuh)
This PR was merged into the 4.2-dev branch.Discussion----------[DependencyInjection] improved message when alias service is not found| Q | A| ------------- | ---| Branch? | 2.8| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#28413| License | MIT| Doc PR |When using the YAML config format, it can be confusing that you need toprefix the aliased service id with an `@` character when passing it asa string, but that you have to omit it when using the `alias` attribute:```yamlfoo: '@app\Foo'foo: alias: 'App\Foo'```This commit will enhance the generated error message in cases where thealiased service id is prefixed with the `@` character in the `alias`option like this:```yamlfoo: alias: '@app\Foo'```Commits-------280ecbc improved message when alias service is not found
2 parentse95ea81 +280ecbc commit7c08e43

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
useSymfony\Component\Console\Output\OutputInterface;
2323
useSymfony\Component\Console\Style\SymfonyStyle;
2424
useSymfony\Component\DependencyInjection\ContainerBuilder;
25+
useSymfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2526
useSymfony\Component\DependencyInjection\Loader\XmlFileLoader;
2627
useSymfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2728

@@ -144,7 +145,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
144145
$options['show_hidden'] =$input->getOption('show-hidden');
145146
$options['raw_text'] =$input->getOption('raw');
146147
$options['output'] =$io;
147-
$helper->describe($io,$object,$options);
148+
149+
try {
150+
$helper->describe($io,$object,$options);
151+
}catch (ServiceNotFoundException$e) {
152+
if ('' !==$e->getId() &&'@' ===$e->getId()[0]) {
153+
thrownewServiceNotFoundException($e->getId(),$e->getSourceId(),null,array(substr($e->getId(),1)));
154+
}
155+
156+
throw$e;
157+
}
148158

149159
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') &&$input->isInteractive()) {
150160
if ($input->getOption('tags')) {

‎src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
useSymfony\Component\DependencyInjection\ContainerBuilder;
1515
useSymfony\Component\DependencyInjection\Exception\InvalidArgumentException;
16+
useSymfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1617
useSymfony\Component\DependencyInjection\Reference;
1718

1819
/**
@@ -53,8 +54,12 @@ public function process(ContainerBuilder $container)
5354
$seenAliasTargets[$targetId] =true;
5455
try {
5556
$definition =$container->getDefinition($targetId);
56-
}catch (InvalidArgumentException$e) {
57-
thrownewInvalidArgumentException(sprintf('Unable to replace alias "%s" with actual definition "%s".',$definitionId,$targetId),null,$e);
57+
}catch (ServiceNotFoundException$e) {
58+
if ('' !==$e->getId() &&'@' ===$e->getId()[0]) {
59+
thrownewServiceNotFoundException($e->getId(),$e->getSourceId(),null,array(substr($e->getId(),1)));
60+
}
61+
62+
throw$e;
5863
}
5964
if ($definition->isPublic()) {
6065
continue;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp