From ed590ca16bc4a5ccb44b711f5c0e797c7d6f6fe2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 10 Aug 2019 19:44:00 +0200 Subject: [PATCH] Revert "bug #33092 [DependencyInjection] Improve an exception message (fabpot)" This reverts commit 2f2d1aa053be969019fb93a0ef9ddf09526f538e, reversing changes made to 07cf9272379db05741a5b573ccf47b3546a8f51c. --- .../Compiler/ResolveClassPass.php | 5 +---- .../Tests/Compiler/ResolveClassPassTest.php | 12 ------------ .../Tests/ContainerBuilderTest.php | 4 ++-- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php index 39e9d797f4..5932472ec6 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php @@ -29,13 +29,10 @@ class ResolveClassPass implements CompilerPassInterface if ($definition->isSynthetic() || null !== $definition->getClass()) { continue; } - if (preg_match('/^\\\\?[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $id)) { + if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $id)) { if ($definition instanceof ChildDefinition && !class_exists($id)) { throw new InvalidArgumentException(sprintf('Service definition "%s" has a parent but no class, and its name looks like a FQCN. Either the class is missing or you want to inherit it from the parent service. To resolve this ambiguity, please rename this service to a non-FQCN (e.g. using dots), or create the missing class.', $id)); } - if ('\\' === $id[0]) { - throw new InvalidArgumentException(sprintf('Service definition "%s" has no class, and its name looks like a FQCN but it starts with a backslash; remove the leading backslash.', $id)); - } $definition->setClass($id); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php index bcc1d002e8..0ab6303164 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php @@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass; class ResolveClassPassTest extends TestCase @@ -59,17 +58,6 @@ class ResolveClassPassTest extends TestCase yield ['\DateTime']; } - public function testWontResolveClassFromClassIdWithLeadingBackslash() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Service definition "\App\Some\Service" has no class, and its name looks like a FQCN but it starts with a backslash; remove the leading backslash.'); - - $container = new ContainerBuilder(); - $container->register('\App\Some\Service'); - - (new ResolveClassPass())->process($container); - } - public function testNonFqcnChildDefinition() { $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 3fede26b80..4113c69414 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php @@ -1288,8 +1288,8 @@ class ContainerBuilderTest extends TestCase public function testNoClassFromNamespaceClassIdWithLeadingSlash() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); - $this->expectExceptionMessage('Service definition "\Symfony\Component\DependencyInjection\Tests\FooClass" has no class, and its name looks like a FQCN but it starts with a backslash; remove the leading backslash.'); + $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectExceptionMessage('The definition for "\Symfony\Component\DependencyInjection\Tests\FooClass" has no class attribute, and appears to reference a class or interface. Please specify the class attribute explicitly or remove the leading backslash by renaming the service to "Symfony\Component\DependencyInjection\Tests\FooClass" to get rid of this error.'); $container = new ContainerBuilder(); $container->register('\\'.FooClass::class);