From 4a1ad7e4c6ff3facc5dab091f552b8efeb176651 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Thu, 25 Jun 2015 12:30:32 +0200 Subject: [PATCH] [Form] Fixed compatibility with FormTypeInterface implementations that don't extend AbstractType --- .../Component/Form/ResolvedFormType.php | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Component/Form/ResolvedFormType.php b/src/Symfony/Component/Form/ResolvedFormType.php index 035ae52f1b..765cb7bf6c 100644 --- a/src/Symfony/Component/Form/ResolvedFormType.php +++ b/src/Symfony/Component/Form/ResolvedFormType.php @@ -200,27 +200,35 @@ class ResolvedFormType implements ResolvedFormTypeInterface $this->innerType->setDefaultOptions($this->optionsResolver); - $reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions'); - $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType'; + if (method_exists($this->innerType, 'configureOptions')) { + $reflector = new \ReflectionMethod($this->innerType, 'setDefaultOptions'); + $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType'; - $reflector = new \ReflectionMethod($this->innerType, 'configureOptions'); - $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType'; + $reflector = new \ReflectionMethod($this->innerType, 'configureOptions'); + $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractType'; - if ($isOldOverwritten && !$isNewOverwritten) { - @trigger_error(get_class($this->innerType).': The FormTypeInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED); + if ($isOldOverwritten && !$isNewOverwritten) { + @trigger_error(get_class($this->innerType).': The FormTypeInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeInterface with Symfony 3.0.', E_USER_DEPRECATED); + } + } else { + @trigger_error(get_class($this->innerType).': The FormTypeInterface::configureOptions() method will be added in Symfony 3.0. You should extend AbstractType or implement it in your classes.', E_USER_DEPRECATED); } foreach ($this->typeExtensions as $extension) { $extension->setDefaultOptions($this->optionsResolver); - $reflector = new \ReflectionMethod($extension, 'setDefaultOptions'); - $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension'; + if (method_exists($extension, 'configureOptions')) { + $reflector = new \ReflectionMethod($extension, 'setDefaultOptions'); + $isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension'; - $reflector = new \ReflectionMethod($extension, 'configureOptions'); - $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension'; + $reflector = new \ReflectionMethod($extension, 'configureOptions'); + $isNewOverwritten = $reflector->getDeclaringClass()->getName() !== 'Symfony\Component\Form\AbstractTypeExtension'; - if ($isOldOverwritten && !$isNewOverwritten) { - @trigger_error(get_class($extension).': The FormTypeExtensionInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeExtensionInterface with Symfony 3.0.', E_USER_DEPRECATED); + if ($isOldOverwritten && !$isNewOverwritten) { + @trigger_error(get_class($extension).': The FormTypeExtensionInterface::setDefaultOptions() method is deprecated since version 2.7 and will be removed in 3.0. Use configureOptions() instead. This method will be added to the FormTypeExtensionInterface with Symfony 3.0.', E_USER_DEPRECATED); + } + } else { + @trigger_error(get_class($this->innerType).': The FormTypeExtensionInterface::configureOptions() method will be added in Symfony 3.0. You should extend AbstractTypeExtension or implement it in your classes.', E_USER_DEPRECATED); } } }