Skip to content

Improved the error message when using "@" in a decorated service #17687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improved the error message when using "@" in a decorated service
  • Loading branch information
javiereguiluz committed Feb 4, 2016
commit 712b271a58cb10b60087d90c79e7cc23e5c069fc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ private function parseDefinition($id, $service, $file)
}

if (isset($service['decorates'])) {
if ('@' === $service['decorates']{0}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could $service['decorates'] be empty here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and by the way, I don't think we use braces anywhere else to access chars in string (everywhere else we use square brackets instead IIRC)

throw new InvalidArgumentException(sprintf('The value of the "decorates" option for the "%s" service must be the id of the service without the "@" prefix (replace "%s" by "%s").', $id, $service['decorates'], substr($service['decorates'], 1)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] replace with [...]

}

$renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null;
$definition->setDecoratedService($service['decorates'], $renameId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,14 @@ public function testTagWithNonStringNameThrowsException()
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('tag_name_no_string.yml');
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" by "foo").
*/
public function testDecoratedServicesWithWrongSyntaxThrowsException()
{
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
$loader->load('bad_decorates.yml');
}
}