bug #19564 Added class existence check if is_subclass_of() fails in compiler passes (SCIF)
This PR was merged into the 2.7 branch.
Discussion
----------
Added class existence check if is_subclass_of() fails in compiler passes
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | comma-separated list of tickets fixed by the PR, if any
| License | MIT
| Doc PR | no
Backport of #19342 to 2.7 branch
Commits
-------
77adea7
Added class existence check if is_subclass_of() fails in compiler passes
This commit is contained in:
commit
ba539190c5
@ -97,9 +97,13 @@ class RegisterListenersPass implements CompilerPassInterface
|
|||||||
|
|
||||||
// We must assume that the class value has been correctly filled, even if the service is created by a factory
|
// We must assume that the class value has been correctly filled, even if the service is created by a factory
|
||||||
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
||||||
|
|
||||||
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
|
$interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
|
||||||
|
|
||||||
if (!is_subclass_of($class, $interface)) {
|
if (!is_subclass_of($class, $interface)) {
|
||||||
|
if (!class_exists($class, false)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
|
||||||
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
|
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,12 @@ class FragmentRendererPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
$class = $container->getParameterBag()->resolveValue($def->getClass());
|
||||||
$interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface';
|
$interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface';
|
||||||
|
|
||||||
if (!is_subclass_of($class, $interface)) {
|
if (!is_subclass_of($class, $interface)) {
|
||||||
|
if (!class_exists($class, false)) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
|
||||||
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
|
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user