From 945f23602b6ffa440669d1eec3d8d9367d3422e9 Mon Sep 17 00:00:00 2001 From: Nicolas Appriou Date: Thu, 14 Dec 2017 10:22:00 +0100 Subject: [PATCH] improve FormType::getType exception message details --- src/Symfony/Component/Form/FormRegistry.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/FormRegistry.php b/src/Symfony/Component/Form/FormRegistry.php index 7da3d2ceb6..8df65de87b 100644 --- a/src/Symfony/Component/Form/FormRegistry.php +++ b/src/Symfony/Component/Form/FormRegistry.php @@ -84,11 +84,14 @@ class FormRegistry implements FormRegistryInterface if (!$type) { // Support fully-qualified class names - if (class_exists($name) && in_array('Symfony\Component\Form\FormTypeInterface', class_implements($name))) { - $type = new $name(); - } else { - throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name)); + if (!class_exists($name)) { + throw new InvalidArgumentException(sprintf('Could not load type "%s": class does not exist.', $name)); } + if (!in_array(FormTypeInterface::class, class_implements($name))) { + throw new InvalidArgumentException(sprintf('Could not load type "%s": class does not implement "%s".', $name, FormTypeInterface::class)); + } + + $type = new $name(); } $this->resolveAndAddType($type);