8000 minor #33108 Revert "bug #33092 [DependencyInjection] Improve an exce… · symfony/symfony@c1e0c1b · GitHub
[go: up one dir, main page]

Skip to content

Commit c1e0c1b

Browse files
minor #33108 Revert "bug #33092 [DependencyInjection] Improve an exception message" (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- Revert "bug #33092 [DependencyInjection] Improve an exception message" | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - As reminded by @ro0NL in #33092 (comment), it looks like we forgot that `CheckDefinitionValidityPass` already checks and suggests for leading slashes. Why didn't you get the exception from `CheckDefinitionValidityPass` @fabpot? Commits ------- ed590ca Revert "bug #33092 [DependencyInjection] Improve an exception message (fabpot)"
2 parents c3ccd2a + ed590ca commit c1e0c1b

File tree

3 files changed

+3
-18
lines changed

3 files changed

+3
-18
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveClassPass.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ public function process(ContainerBuilder $container)
2929
if ($definition->isSynthetic() || null !== $definition->getClass()) {
3030
continue;
3131
}
32-
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)) {
32+
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)) {
3333
if ($definition instanceof ChildDefinition && !class_exists($id)) {
3434
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));
3535
}
36-
if ('\\' === $id[0]) {
37-
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));
38-
}
3936
$definition->setClass($id);
4037
}
4138
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveClassPassTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\ChildDefinition;
1616
use Symfony\Component\DependencyInjection\Compiler\ResolveClassPass;
1717
use Symfony\Component\DependencyInjection\ContainerBuilder;
18-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1918
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2019

2120
class ResolveClassPassTest extends TestCase
@@ -59,17 +58,6 @@ public function provideInvalidClassId()
5958
yield ['\DateTime'];
6059
}
6160

62-
public function testWontResolveClassFromClassIdWithLeadingBackslash()
63-
{
64-
$this->expectException(InvalidArgumentException::class);
65-
$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.');
66-
67-
$container = new ContainerBuilder();
68-
$container->register('\App\Some\Service');
69-
70-
(new ResolveClassPass())->process($container);
71-
}
72-
7361
public function testNonFqcnChildDefinition()
7462
{
7563
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,8 @@ public function testNoClassFromGlobalNamespaceClassIdWithLeadingSlash()
12881288

12891289
public function testNoClassFromNamespaceClassIdWithLeadingSlash()
12901290
{
1291-
$this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException');
1292-
$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.');
1291+
$this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException');
1292+
$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.');
12931293
$container = new ContainerBuilder();
12941294

12951295
$container->register('\\'.FooClass::class);

0 commit comments

Comments
 (0)
0