From 72db6e706847c3530f7086f7361b475fe4754649 Mon Sep 17 00:00:00 2001 From: Alexander Zhuravlev Date: Tue, 12 Jul 2016 14:13:14 +1200 Subject: [PATCH] Added class existence check if is_subclass_of() fails in compiler passes --- .../DependencyInjection/RegisterListenersPass.php | 6 +++++- .../HttpKernel/DependencyInjection/FragmentRendererPass.php | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php index ebfe435f87..326bfd184f 100644 --- a/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php +++ b/src/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php @@ -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 $class = $container->getParameterBag()->resolveValue($def->getClass()); - $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface'; + 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)); } diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php index 3187e943c9..0c4cecef66 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php @@ -54,7 +54,12 @@ class FragmentRendererPass implements CompilerPassInterface $class = $container->getParameterBag()->resolveValue($def->getClass()); $interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface'; + 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)); }