10000 bug #19342 Added class existence check if is_subclass_of() fails in c… · symfony/symfony@00ab2d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 00ab2d6

Browse files
committed
bug #19342 Added class existence check if is_subclass_of() fails in compiler passes (SCIF)
This PR was merged into the 2.8 branch. Discussion ---------- Added class existence check if is_subclass_of() fails in compiler passes | Q | A | ------------- | --- | Branch? | 2.8-3.1 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - If you create an event subscriber and make typo in file name it will cause next error: ``` [InvalidArgumentException] Service "event.notification_subscriber" must implement interface "Symfony\Component\EventDispatcher\EventSubscriberInterface". ``` That's because of `is_subclass_of()` fails on class absentee. I made error message more clear. Commits ------- 72db6e7 Added class existence check if is_subclass_of() fails in compiler passes
2 parents 88aff45 + 72db6e7 commit 00ab2d6

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ public function process(ContainerBuilder $container)
9797

9898
// We must assume that the class value has been correctly filled, even if the service is created by a factory
9999
$class = $container->getParameterBag()->resolveValue($def->getClass());
100-
101100
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
101+
102102
if (!is_subclass_of($class, $interface)) {
103+
if (!class_exists($class, false)) {
104+
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
105+
}
106+
103107
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
104108
}
105109

src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public function process(ContainerBuilder $container)
5454

5555
$class = $container->getParameterBag()->resolveValue($def->getClass());
5656
$interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface';
57+
5758
if (!is_subclass_of($class, $interface)) {
59+
if (!class_exists($class, false)) {
60+
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
61+
}
62+
5863
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
5964
}
6065

0 commit comments

Comments
 (0)
0