From 712b271a58cb10b60087d90c79e7cc23e5c069fc Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 4 Feb 2016 15:21:55 +0100 Subject: [PATCH 1/4] Improved the error message when using "@" in a decorated service --- .../DependencyInjection/Loader/YamlFileLoader.php | 4 ++++ .../Tests/Loader/YamlFileLoaderTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 8036933ad5099..70a3871352fc9 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -288,6 +288,10 @@ private function parseDefinition($id, $service, $file) } if (isset($service['decorates'])) { + if ('@' === $service['decorates']{0}) { + 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))); + } + $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null; $definition->setDecoratedService($service['decorates'], $renameId); } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index bc3ca7762209a..44a3250507643 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -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'); + } } From 3e737134bb18b4fe48ce2bb9f80bf1bca46b6095 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Thu, 4 Feb 2016 15:22:58 +0100 Subject: [PATCH 2/4] Added missing fixtures file --- .../Tests/Fixtures/yaml/bad_decorates.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_decorates.yml diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_decorates.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_decorates.yml new file mode 100644 index 0000000000000..79c048a847e2d --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/bad_decorates.yml @@ -0,0 +1,7 @@ +services: + foo: + class: stdClass + bar: + class: stdClass + decorates: "@foo" + arguments: ["@bar.inner"] From f3367c93e38a886e56f23453b7a40ea30bbc1d70 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 9 Feb 2016 17:42:01 +0100 Subject: [PATCH 3/4] Minor syntax refactor --- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index 70a3871352fc9..a4b9d0c458ed2 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -288,7 +288,7 @@ private function parseDefinition($id, $service, $file) } if (isset($service['decorates'])) { - if ('@' === $service['decorates']{0}) { + if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) { 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))); } From 94a0323d7e9a6abd2a19a25099e658965b6b6ebc Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 9 Feb 2016 18:11:11 +0100 Subject: [PATCH 4/4] Fixed a grammar issue --- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 2 +- .../DependencyInjection/Tests/Loader/YamlFileLoaderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index a4b9d0c458ed2..f57ba587c834b 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -289,7 +289,7 @@ private function parseDefinition($id, $service, $file) if (isset($service['decorates'])) { if ('' !== $service['decorates'] && '@' === $service['decorates'][0]) { - 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))); + 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" with "%s").', $id, $service['decorates'], substr($service['decorates'], 1))); } $renameId = isset($service['decoration_inner_name']) ? $service['decoration_inner_name'] : null; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 44a3250507643..78f9bafc154f5 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -300,7 +300,7 @@ public function testTagWithNonStringNameThrowsException() /** * @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"). + * @expectedExceptionMessage The value of the "decorates" option for the "bar" service must be the id of the service without the "@" prefix (replace "@foo" with "foo"). */ public function testDecoratedServicesWithWrongSyntaxThrowsException() { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy