From bf9382e6cdfa792b57bc2bd1111e240c9f8df36f Mon Sep 17 00:00:00 2001 From: Alexander Kotynia Date: Mon, 15 Apr 2013 23:11:02 +0300 Subject: [PATCH] [Form] Make exception handling consistent with other components --- .../Component/Form/AbstractExtension.php | 4 +- src/Symfony/Component/Form/Button.php | 32 +++--- src/Symfony/Component/Form/ButtonBuilder.php | 108 +++++++++--------- src/Symfony/Component/Form/CHANGELOG.md | 3 + .../Form/Exception/AlreadyBoundException.php | 2 +- .../Form/Exception/ErrorMappingException.php | 2 +- .../InvalidConfigurationException.php | 2 +- ...eationException.php => LogicException.php} | 6 +- .../Exception/NotInitializedException.php | 16 --- .../Form/Exception/NotValidException.php | 16 --- ...Exception.php => OutOfBoundsException.php} | 6 +- .../Form/Exception/StringCastException.php | 2 +- .../TransformationFailedException.php | 2 +- .../Form/Exception/TypeLoaderException.php | 16 --- .../Exception/UnexpectedTypeException.php | 2 +- .../Extension/Core/ChoiceList/ChoiceList.php | 5 +- .../Core/ChoiceList/LazyChoiceList.php | 4 +- .../Core/ChoiceList/ObjectChoiceList.php | 5 +- .../Form/Extension/Core/Type/ChoiceType.php | 4 +- .../Form/Extension/Core/Type/FormType.php | 4 +- .../DependencyInjectionExtension.php | 5 +- .../EventListener/BindRequestListener.php | 4 +- .../ViolationMapper/ViolationPath.php | 11 +- src/Symfony/Component/Form/Form.php | 20 ++-- src/Symfony/Component/Form/FormBuilder.php | 4 +- .../Component/Form/FormBuilderInterface.php | 2 +- .../Component/Form/FormConfigBuilder.php | 8 +- .../Component/Form/FormExtensionInterface.php | 2 +- .../Component/Form/FormFactoryInterface.php | 12 +- src/Symfony/Component/Form/FormInterface.php | 6 +- src/Symfony/Component/Form/FormRegistry.php | 4 +- .../Component/Form/FormRegistryInterface.php | 4 +- src/Symfony/Component/Form/FormRenderer.php | 9 +- src/Symfony/Component/Form/FormView.php | 6 +- src/Symfony/Component/Form/Guess/Guess.php | 6 +- .../Component/Form/PreloadedExtension.php | 4 +- .../Component/Form/ResolvedFormType.php | 4 +- .../Form/ResolvedFormTypeFactoryInterface.php | 4 +- .../Core/ChoiceList/LazyChoiceListTest.php | 2 +- .../Core/ChoiceList/ObjectChoiceListTest.php | 2 +- .../Tests/Fixtures/FixedDataTransformer.php | 5 +- .../Component/Form/Tests/FormBuilderTest.php | 2 +- .../Component/Form/Tests/FormConfigTest.php | 5 +- .../Component/Form/Tests/FormRegistryTest.php | 4 +- .../Component/Form/Tests/SimpleFormTest.php | 14 +-- 45 files changed, 178 insertions(+), 212 deletions(-) rename src/Symfony/Component/Form/Exception/{CreationException.php => LogicException.php} (63%) delete mode 100644 src/Symfony/Component/Form/Exception/NotInitializedException.php delete mode 100644 src/Symfony/Component/Form/Exception/NotValidException.php rename src/Symfony/Component/Form/Exception/{TypeDefinitionException.php => OutOfBoundsException.php} (60%) delete mode 100644 src/Symfony/Component/Form/Exception/TypeLoaderException.php diff --git a/src/Symfony/Component/Form/AbstractExtension.php b/src/Symfony/Component/Form/AbstractExtension.php index daa57e768f..4db77b9bb5 100644 --- a/src/Symfony/Component/Form/AbstractExtension.php +++ b/src/Symfony/Component/Form/AbstractExtension.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\UnexpectedTypeException; /** @@ -53,7 +53,7 @@ abstract class AbstractExtension implements FormExtensionInterface } if (!isset($this->types[$name])) { - throw new Exception(sprintf('The type "%s" can not be loaded by this extension', $name)); + throw new InvalidArgumentException(sprintf('The type "%s" can not be loaded by this extension', $name)); } return $this->types[$name]; diff --git a/src/Symfony/Component/Form/Button.php b/src/Symfony/Component/Form/Button.php index 77af61b8d8..d98ef87844 100644 --- a/src/Symfony/Component/Form/Button.php +++ b/src/Symfony/Component/Form/Button.php @@ -65,11 +65,11 @@ class Button implements \IteratorAggregate, FormInterface * * @param mixed $offset * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function offsetGet($offset) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -80,11 +80,11 @@ class Button implements \IteratorAggregate, FormInterface * @param mixed $offset * @param mixed $value * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function offsetSet($offset, $value) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -94,11 +94,11 @@ class Button implements \IteratorAggregate, FormInterface * * @param mixed $offset * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function offsetUnset($offset) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -126,11 +126,11 @@ class Button implements \IteratorAggregate, FormInterface * @param null $type * @param array $options * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function add($child, $type = null, array $options = array()) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -140,11 +140,11 @@ class Button implements \IteratorAggregate, FormInterface * * @param string $name * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function get($name) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -166,11 +166,11 @@ class Button implements \IteratorAggregate, FormInterface * * @param string $name * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function remove($name) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -196,11 +196,11 @@ class Button implements \IteratorAggregate, FormInterface * * @param string $modelData * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setData($modelData) { - throw new \BadMethodCallException('Buttons cannot have data.'); + throw new BadMethodCallException('Buttons cannot have data.'); } /** @@ -288,11 +288,11 @@ class Button implements \IteratorAggregate, FormInterface * * @param FormError $error * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function addError(FormError $error) { - throw new \BadMethodCallException('Buttons cannot have errors.'); + throw new BadMethodCallException('Buttons cannot have errors.'); } /** diff --git a/src/Symfony/Component/Form/ButtonBuilder.php b/src/Symfony/Component/Form/ButtonBuilder.php index 66ce61ab53..47892d8e1c 100644 --- a/src/Symfony/Component/Form/ButtonBuilder.php +++ b/src/Symfony/Component/Form/ButtonBuilder.php @@ -12,8 +12,8 @@ namespace Symfony\Component\Form; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\Form\Exception\FormException; use Symfony\Component\Form\Exception\InvalidArgumentException; +use Symfony\Component\Form\Exception\BadMethodCallException; /** * A builder for {@link Button} instances. @@ -58,7 +58,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * @param string $name The name of the button. * @param array $options The button's options. * - * @throws FormException If the name is empty. + * @throws InvalidArgumentException If the name is empty. */ public function __construct($name, array $options) { @@ -79,11 +79,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * @param string|FormTypeInterface $type * @param array $options * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function add($child, $type = null, array $options = array()) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -95,11 +95,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * @param string|FormTypeInterface $type * @param array $options * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function create($name, $type = null, array $options = array()) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -109,11 +109,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param string $name * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function get($name) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -123,11 +123,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param string $name * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function remove($name) { - throw new \BadMethodCallException('Buttons cannot have children.'); + throw new BadMethodCallException('Buttons cannot have children.'); } /** @@ -171,11 +171,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * @param callable $listener * @param integer $priority * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function addEventListener($eventName, $listener, $priority = 0) { - throw new \BadMethodCallException('Buttons do not support event listeners.'); + throw new BadMethodCallException('Buttons do not support event listeners.'); } /** @@ -185,11 +185,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param EventSubscriberInterface $subscriber * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function addEventSubscriber(EventSubscriberInterface $subscriber) { - throw new \BadMethodCallException('Buttons do not support event subscribers.'); + throw new BadMethodCallException('Buttons do not support event subscribers.'); } /** @@ -200,11 +200,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * @param DataTransformerInterface $viewTransformer * @param Boolean $forcePrepend * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false) { - throw new \BadMethodCallException('Buttons do not support data transformers.'); + throw new BadMethodCallException('Buttons do not support data transformers.'); } /** @@ -212,11 +212,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * This method should not be invoked. * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function resetViewTransformers() { - throw new \BadMethodCallException('Buttons do not support data transformers.'); + throw new BadMethodCallException('Buttons do not support data transformers.'); } /** @@ -227,11 +227,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * @param DataTransformerInterface $modelTransformer * @param Boolean $forceAppend * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false) { - throw new \BadMethodCallException('Buttons do not support data transformers.'); + throw new BadMethodCallException('Buttons do not support data transformers.'); } /** @@ -239,11 +239,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * This method should not be invoked. * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function resetModelTransformers() { - throw new \BadMethodCallException('Buttons do not support data transformers.'); + throw new BadMethodCallException('Buttons do not support data transformers.'); } /** @@ -269,11 +269,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param DataMapperInterface $dataMapper * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setDataMapper(DataMapperInterface $dataMapper = null) { - throw new \BadMethodCallException('Buttons do not support data mappers.'); + throw new BadMethodCallException('Buttons do not support data mappers.'); } /** @@ -295,11 +295,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param mixed $emptyData * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setEmptyData($emptyData) { - throw new \BadMethodCallException('Buttons do not support empty data.'); + throw new BadMethodCallException('Buttons do not support empty data.'); } /** @@ -309,11 +309,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $errorBubbling * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setErrorBubbling($errorBubbling) { - throw new \BadMethodCallException('Buttons do not support error bubbling.'); + throw new BadMethodCallException('Buttons do not support error bubbling.'); } /** @@ -323,11 +323,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $required * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setRequired($required) { - throw new \BadMethodCallException('Buttons cannot be required.'); + throw new BadMethodCallException('Buttons cannot be required.'); } /** @@ -337,11 +337,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param null $propertyPath * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setPropertyPath($propertyPath) { - throw new \BadMethodCallException('Buttons do not support property paths.'); + throw new BadMethodCallException('Buttons do not support property paths.'); } /** @@ -351,11 +351,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $mapped * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setMapped($mapped) { - throw new \BadMethodCallException('Buttons do not support data mapping.'); + throw new BadMethodCallException('Buttons do not support data mapping.'); } /** @@ -365,11 +365,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $byReference * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setByReference($byReference) { - throw new \BadMethodCallException('Buttons do not support data mapping.'); + throw new BadMethodCallException('Buttons do not support data mapping.'); } /** @@ -379,11 +379,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $virtual * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setVirtual($virtual) { - throw new \BadMethodCallException('Buttons cannot be virtual.'); + throw new BadMethodCallException('Buttons cannot be virtual.'); } /** @@ -393,11 +393,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $compound * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setCompound($compound) { - throw new \BadMethodCallException('Buttons cannot be compound.'); + throw new BadMethodCallException('Buttons cannot be compound.'); } /** @@ -419,11 +419,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param array $data * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setData($data) { - throw new \BadMethodCallException('Buttons do not support data.'); + throw new BadMethodCallException('Buttons do not support data.'); } /** @@ -433,11 +433,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $locked * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setDataLocked($locked) { - throw new \BadMethodCallException('Buttons do not support data locking.'); + throw new BadMethodCallException('Buttons do not support data locking.'); } /** @@ -449,11 +449,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @return void * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setFormFactory(FormFactoryInterface $formFactory) { - throw new \BadMethodCallException('Buttons do not support form factories.'); + throw new BadMethodCallException('Buttons do not support form factories.'); } /** @@ -461,11 +461,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param string $action * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setAction($action) { - throw new \BadMethodCallException('Buttons do not support actions.'); + throw new BadMethodCallException('Buttons do not support actions.'); } /** @@ -473,11 +473,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param string $method * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setMethod($method) { - throw new \BadMethodCallException('Buttons do not support methods.'); + throw new BadMethodCallException('Buttons do not support methods.'); } /** @@ -485,11 +485,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param FormProcessorInterface $formProcessor * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setFormProcessor(FormProcessorInterface $formProcessor) { - throw new \BadMethodCallException('Buttons do not support form processors.'); + throw new BadMethodCallException('Buttons do not support form processors.'); } /** @@ -497,11 +497,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface * * @param Boolean $inheritData * - * @throws \BadMethodCallException + * @throws BadMethodCallException */ public function setInheritData($inheritData) { - throw new \BadMethodCallException('Buttons do not support data inheritance.'); + throw new BadMethodCallException('Buttons do not support data inheritance.'); } /** diff --git a/src/Symfony/Component/Form/CHANGELOG.md b/src/Symfony/Component/Form/CHANGELOG.md index ecea1be9ac..ed966f03f1 100644 --- a/src/Symfony/Component/Form/CHANGELOG.md +++ b/src/Symfony/Component/Form/CHANGELOG.md @@ -15,6 +15,9 @@ CHANGELOG * deprecated VirtualFormAwareIterator in favor of InheritDataAwareIterator * [BC BREAK] removed the "array" type hint from DataMapperInterface * improved forms inheriting their parent data to actually return that data from getData(), getNormData() and getViewData() + * added component-level exceptions for various SPL exceptions + changed all uses of the deprecated Exception class to use more specialized exceptions instead + removed NotInitializedException, NotValidException, TypeDefinitionException, TypeLoaderException, CreationException 2.2.0 ----- diff --git a/src/Symfony/Component/Form/Exception/AlreadyBoundException.php b/src/Symfony/Component/Form/Exception/AlreadyBoundException.php index 9679725e9f..5c1b7c52bc 100644 --- a/src/Symfony/Component/Form/Exception/AlreadyBoundException.php +++ b/src/Symfony/Component/Form/Exception/AlreadyBoundException.php @@ -11,6 +11,6 @@ namespace Symfony\Component\Form\Exception; -class AlreadyBoundException extends Exception +class AlreadyBoundException extends LogicException { } diff --git a/src/Symfony/Component/Form/Exception/ErrorMappingException.php b/src/Symfony/Component/Form/Exception/ErrorMappingException.php index adbb2deb51..a696849264 100644 --- a/src/Symfony/Component/Form/Exception/ErrorMappingException.php +++ b/src/Symfony/Component/Form/Exception/ErrorMappingException.php @@ -11,6 +11,6 @@ namespace Symfony\Component\Form\Exception; -class ErrorMappingException extends Exception +class ErrorMappingException extends RuntimeException { } diff --git a/src/Symfony/Component/Form/Exception/InvalidConfigurationException.php b/src/Symfony/Component/Form/Exception/InvalidConfigurationException.php index 08c7b72815..daa0c42f58 100644 --- a/src/Symfony/Component/Form/Exception/InvalidConfigurationException.php +++ b/src/Symfony/Component/Form/Exception/InvalidConfigurationException.php @@ -11,6 +11,6 @@ namespace Symfony\Component\Form\Exception; -class InvalidConfigurationException extends Exception +class InvalidConfigurationException extends InvalidArgumentException { } diff --git a/src/Symfony/Component/Form/Exception/CreationException.php b/src/Symfony/Component/Form/Exception/LogicException.php similarity index 63% rename from src/Symfony/Component/Form/Exception/CreationException.php rename to src/Symfony/Component/Form/Exception/LogicException.php index e6c4b4e173..848780215b 100644 --- a/src/Symfony/Component/Form/Exception/CreationException.php +++ b/src/Symfony/Component/Form/Exception/LogicException.php @@ -12,10 +12,10 @@ namespace Symfony\Component\Form\Exception; /** - * Thrown when a form could not be constructed by a FormFactory + * Base LogicException for Form component. * - * @author Bernhard Schussek + * @author Alexander Kotynia */ -class CreationException extends Exception +class LogicException extends \LogicException implements ExceptionInterface { } diff --git a/src/Symfony/Component/Form/Exception/NotInitializedException.php b/src/Symfony/Component/Form/Exception/NotInitializedException.php deleted file mode 100644 index 2c416ede3f..0000000000 --- a/src/Symfony/Component/Form/Exception/NotInitializedException.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Form\Exception; - -class NotInitializedException extends Exception -{ -} diff --git a/src/Symfony/Component/Form/Exception/NotValidException.php b/src/Symfony/Component/Form/Exception/NotValidException.php deleted file mode 100644 index 42c5f4ffbd..0000000000 --- a/src/Symfony/Component/Form/Exception/NotValidException.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Form\Exception; - -class NotValidException extends Exception -{ -} diff --git a/src/Symfony/Component/Form/Exception/TypeDefinitionException.php b/src/Symfony/Component/Form/Exception/OutOfBoundsException.php similarity index 60% rename from src/Symfony/Component/Form/Exception/TypeDefinitionException.php rename to src/Symfony/Component/Form/Exception/OutOfBoundsException.php index 0567350502..44d3116630 100644 --- a/src/Symfony/Component/Form/Exception/TypeDefinitionException.php +++ b/src/Symfony/Component/Form/Exception/OutOfBoundsException.php @@ -12,10 +12,10 @@ namespace Symfony\Component\Form\Exception; /** - * Thrown when a form type is configured incorrectly + * Base OutOfBoundsException for Form component. * - * @author Bernhard Schussek + * @author Alexander Kotynia */ -class TypeDefinitionException extends Exception +class OutOfBoundsException extends \OutOfBoundsException implements ExceptionInterface { } diff --git a/src/Symfony/Component/Form/Exception/StringCastException.php b/src/Symfony/Component/Form/Exception/StringCastException.php index d4bdf0a7fe..f9b51d6049 100644 --- a/src/Symfony/Component/Form/Exception/StringCastException.php +++ b/src/Symfony/Component/Form/Exception/StringCastException.php @@ -11,6 +11,6 @@ namespace Symfony\Component\Form\Exception; -class StringCastException extends Exception +class StringCastException extends RuntimeException { } diff --git a/src/Symfony/Component/Form/Exception/TransformationFailedException.php b/src/Symfony/Component/Form/Exception/TransformationFailedException.php index 2bbefbabc8..d32896e69c 100644 --- a/src/Symfony/Component/Form/Exception/TransformationFailedException.php +++ b/src/Symfony/Component/Form/Exception/TransformationFailedException.php @@ -16,6 +16,6 @@ namespace Symfony\Component\Form\Exception; * * @author Bernhard Schussek */ -class TransformationFailedException extends \RuntimeException implements ExceptionInterface +class TransformationFailedException extends RuntimeException { } diff --git a/src/Symfony/Component/Form/Exception/TypeLoaderException.php b/src/Symfony/Component/Form/Exception/TypeLoaderException.php deleted file mode 100644 index a257b504fa..0000000000 --- a/src/Symfony/Component/Form/Exception/TypeLoaderException.php +++ /dev/null @@ -1,16 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Form\Exception; - -class TypeLoaderException extends Exception -{ -} diff --git a/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php b/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php index 77cabb7d7b..474e244bd8 100644 --- a/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php +++ b/src/Symfony/Component/Form/Exception/UnexpectedTypeException.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form\Exception; -class UnexpectedTypeException extends Exception +class UnexpectedTypeException extends InvalidArgumentException { public function __construct($value, $expectedType) { diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php index d8f2a16561..f9d381cd04 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList; use Symfony\Component\Form\FormConfigBuilder; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\InvalidConfigurationException; +use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Extension\Core\View\ChoiceView; /** @@ -254,7 +255,7 @@ class ChoiceList implements ChoiceListInterface * @param array $labels The labels corresponding to the choices. * @param array $preferredChoices The preferred choices. * - * @throws \InvalidArgumentException If the structures of the choices and labels array do not match. + * @throws InvalidArgumentException If the structures of the choices and labels array do not match. * @throws InvalidConfigurationException If no valid value or index could be created for a choice. */ protected function addChoices(array &$bucketForPreferred, array &$bucketForRemaining, $choices, array $labels, array $preferredChoices) @@ -262,7 +263,7 @@ class ChoiceList implements ChoiceListInterface // Add choices to the nested buckets foreach ($choices as $group => $choice) { if (!array_key_exists($group, $labels)) { - throw new \InvalidArgumentException('The structures of the choices and labels array do not match.'); + throw new InvalidArgumentException('The structures of the choices and labels array do not match.'); } if (is_array($choice)) { diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php index 75742a2d9c..996f900cf3 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\InvalidArgumentException; /** * A choice list that is loaded lazily @@ -141,7 +141,7 @@ abstract class LazyChoiceList implements ChoiceListInterface $choiceList = $this->loadChoiceList(); if (!$choiceList instanceof ChoiceListInterface) { - throw new Exception(sprintf('loadChoiceList() should return a ChoiceListInterface instance. Got %s', gettype($choiceList))); + throw new InvalidArgumentException(sprintf('loadChoiceList() should return a ChoiceListInterface instance. Got %s', gettype($choiceList))); } $this->choiceList = $choiceList; diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php index 6c3be2c4d1..0a153883a3 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ObjectChoiceList.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList; use Symfony\Component\Form\Exception\StringCastException; +use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; use Symfony\Component\PropertyAccess\PropertyAccess; @@ -103,7 +104,7 @@ class ObjectChoiceList extends ChoiceList * @param array $labels Ignored. * @param array $preferredChoices The choices to display with priority. * - * @throws \InvalidArgumentException When passing a hierarchy of choices and using + * @throws InvalidArgumentException When passing a hierarchy of choices and using * the "groupPath" option at the same time. */ protected function initialize($choices, array $labels, array $preferredChoices) @@ -113,7 +114,7 @@ class ObjectChoiceList extends ChoiceList foreach ($choices as $i => $choice) { if (is_array($choice)) { - throw new \InvalidArgumentException('You should pass a plain object array (without groups) when using the "groupPath" option.'); + throw new InvalidArgumentException('You should pass a plain object array (without groups) when using the "groupPath" option.'); } try { diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 20d72d7854..446a74dd6e 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList; use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener; use Symfony\Component\Form\Extension\Core\EventListener\FixCheckboxInputListener; @@ -41,7 +41,7 @@ class ChoiceType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) { - throw new Exception('Either the option "choices" or "choice_list" must be set.'); + throw new LogicException('Either the option "choices" or "choice_list" must be set.'); } if ($options['expanded']) { diff --git a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php index 473b009ea3..39e16799c4 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/FormType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/FormType.php @@ -16,7 +16,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\PropertyAccess\PropertyAccess; @@ -74,7 +74,7 @@ class FormType extends BaseType if ($view->parent) { if ('' === $name) { - throw new Exception('Form node with empty name can be used only as root form node.'); + throw new LogicException('Form node with empty name can be used only as root form node.'); } // Complex fields are read-only if they themselves or their parents are. diff --git a/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php b/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php index 06936643a1..6637ac8c63 100644 --- a/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php +++ b/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\DependencyInjection; use Symfony\Component\Form\FormExtensionInterface; use Symfony\Component\Form\FormTypeGuesserChain; +use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\ContainerInterface; class DependencyInjectionExtension implements FormExtensionInterface @@ -40,13 +41,13 @@ class DependencyInjectionExtension implements FormExtensionInterface public function getType($name) { if (!isset($this->typeServiceIds[$name])) { - throw new \InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $name)); + throw new InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $name)); } $type = $this->container->get($this->typeServiceIds[$name]); if ($type->getName() !== $name) { - throw new \InvalidArgumentException( + throw new InvalidArgumentException( sprintf('The type name specified for the service "%s" does not match the actual name. Expected "%s", given "%s"', $this->typeServiceIds[$name], $name, diff --git a/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php b/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php index 3b4359ed5c..f71113f01f 100644 --- a/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php +++ b/src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php @@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\HttpFoundation\EventListener; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvent; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\LogicException; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\Request; @@ -80,7 +80,7 @@ class BindRequestListener implements EventSubscriberInterface break; default: - throw new Exception(sprintf( + throw new LogicException(sprintf( 'The request method "%s" is not supported', $request->getMethod() )); diff --git a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPath.php b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPath.php index 6035f66c8e..06d091954e 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPath.php +++ b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationPath.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; +use Symfony\Component\Form\Exception\OutOfBoundsException; use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\PropertyAccess\PropertyPathInterface; @@ -155,7 +156,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface public function getElement($index) { if (!isset($this->elements[$index])) { - throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); + throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); } return $this->elements[$index]; @@ -167,7 +168,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface public function isProperty($index) { if (!isset($this->isIndex[$index])) { - throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); + throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); } return !$this->isIndex[$index]; @@ -179,7 +180,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface public function isIndex($index) { if (!isset($this->isIndex[$index])) { - throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); + throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); } return $this->isIndex[$index]; @@ -201,12 +202,12 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface * * @return Boolean Whether the element maps to a form. * - * @throws \OutOfBoundsException If the offset is invalid. + * @throws OutOfBoundsException If the offset is invalid. */ public function mapsForm($index) { if (!isset($this->mapsForm[$index])) { - throw new \OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); + throw new OutOfBoundsException(sprintf('The index %s is not within the violation path', $index)); } return $this->mapsForm[$index]; diff --git a/src/Symfony/Component/Form/Form.php b/src/Symfony/Component/Form/Form.php index db884cf6f5..4600fd043a 100644 --- a/src/Symfony/Component/Form/Form.php +++ b/src/Symfony/Component/Form/Form.php @@ -11,12 +11,12 @@ namespace Symfony\Component\Form; -use Symfony\Component\Form\Exception\BadMethodCallException; -use Symfony\Component\Form\Exception\Exception; use Symfony\Component\Form\Exception\RuntimeException; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\AlreadyBoundException; use Symfony\Component\Form\Exception\TransformationFailedException; +use Symfony\Component\Form\Exception\LogicException; +use Symfony\Component\Form\Exception\OutOfBoundsException; use Symfony\Component\Form\Util\FormUtil; use Symfony\Component\Form\Util\InheritDataAwareIterator; use Symfony\Component\PropertyAccess\PropertyPath; @@ -146,7 +146,7 @@ class Form implements \IteratorAggregate, FormInterface * * @param FormConfigInterface $config The form configuration. * - * @throws Exception if a data mapper is not provided for a compound form + * @throws LogicException if a data mapper is not provided for a compound form */ public function __construct(FormConfigInterface $config) { @@ -154,7 +154,7 @@ class Form implements \IteratorAggregate, FormInterface // `setData` and `add` will not lead to the correct population of // the child forms. if ($config->getCompound() && !$config->getDataMapper()) { - throw new Exception('Compound forms need a data mapper'); + throw new LogicException('Compound forms need a data mapper'); } // If the form inherits the data from its parent, it is not necessary @@ -249,7 +249,7 @@ class Form implements \IteratorAggregate, FormInterface } if (null !== $parent && '' === $this->config->getName()) { - throw new Exception('A form with an empty name cannot have a parent form.'); + throw new LogicException('A form with an empty name cannot have a parent form.'); } $this->parent = $parent; @@ -340,7 +340,7 @@ class Form implements \IteratorAggregate, FormInterface if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) { $expectedType = 'scalar, array or an instance of \ArrayAccess'; - throw new Exception( + throw new LogicException( 'The form\'s view data is expected to be of type '.$expectedType.', ' . 'but is '.$actualType.'. You ' . 'can avoid this error by setting the "data_class" option to ' . @@ -350,7 +350,7 @@ class Form implements \IteratorAggregate, FormInterface } if (null !== $dataClass && !$viewData instanceof $dataClass) { - throw new Exception( + throw new LogicException( 'The form\'s view data is expected to be an instance of class ' . $dataClass.', but is '. $actualType.'. You can avoid this error ' . 'by setting the "data_class" option to null or by adding a view ' . @@ -729,7 +729,7 @@ class Form implements \IteratorAggregate, FormInterface } if (!$this->config->getCompound()) { - throw new Exception('You cannot add children to a simple form. Maybe you should set the option "compound" to true?'); + throw new LogicException('You cannot add children to a simple form. Maybe you should set the option "compound" to true?'); } // Obtain the view data @@ -815,7 +815,7 @@ class Form implements \IteratorAggregate, FormInterface return $this->children[$name]; } - throw new \OutOfBoundsException(sprintf('Child "%s" does not exist.', $name)); + throw new OutOfBoundsException(sprintf('Child "%s" does not exist.', $name)); } /** @@ -851,7 +851,7 @@ class Form implements \IteratorAggregate, FormInterface * @param FormInterface $child The child to be added. * * @throws AlreadyBoundException If the form has already been bound. - * @throws FormException When trying to add a child to a non-compound form. + * @throws LogicException When trying to add a child to a non-compound form. * * @see self::add() */ diff --git a/src/Symfony/Component/Form/FormBuilder.php b/src/Symfony/Component/Form/FormBuilder.php index a778c9e09d..986f43c5ae 100644 --- a/src/Symfony/Component/Form/FormBuilder.php +++ b/src/Symfony/Component/Form/FormBuilder.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Form; use Symfony\Component\Form\Exception\BadMethodCallException; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -126,7 +126,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB return $this->children[$name]; } - throw new Exception(sprintf('The child with the name "%s" does not exist.', $name)); + throw new InvalidArgumentException(sprintf('The child with the name "%s" does not exist.', $name)); } /** diff --git a/src/Symfony/Component/Form/FormBuilderInterface.php b/src/Symfony/Component/Form/FormBuilderInterface.php index d862c49bf5..1dc4a64e7b 100644 --- a/src/Symfony/Component/Form/FormBuilderInterface.php +++ b/src/Symfony/Component/Form/FormBuilderInterface.php @@ -49,7 +49,7 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild * * @return FormBuilderInterface The builder for the child * - * @throws Exception\FormException if the given child does not exist + * @throws Exception\InvalidArgumentException if the given child does not exist */ public function get($name); diff --git a/src/Symfony/Component/Form/FormConfigBuilder.php b/src/Symfony/Component/Form/FormConfigBuilder.php index 0927c72921..b839fa1065 100644 --- a/src/Symfony/Component/Form/FormConfigBuilder.php +++ b/src/Symfony/Component/Form/FormConfigBuilder.php @@ -185,7 +185,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface * @param EventDispatcherInterface $dispatcher The event dispatcher * @param array $options The form options * - * @throws \InvalidArgumentException If the data class is not a valid class or if + * @throws InvalidArgumentException If the data class is not a valid class or if * the name contains invalid characters. */ public function __construct($name, $dataClass, EventDispatcherInterface $dispatcher, array $options = array()) @@ -193,7 +193,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface self::validateName($name); if (null !== $dataClass && !class_exists($dataClass)) { - throw new \InvalidArgumentException(sprintf('The data class "%s" is not a valid class.', $dataClass)); + throw new InvalidArgumentException(sprintf('The data class "%s" is not a valid class.', $dataClass)); } $this->name = (string) $name; @@ -865,7 +865,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface * @param string|integer $name The tested form name. * * @throws UnexpectedTypeException If the name is not a string or an integer. - * @throws \InvalidArgumentException If the name contains invalid characters. + * @throws InvalidArgumentException If the name contains invalid characters. */ public static function validateName($name) { @@ -874,7 +874,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface } if (!self::isValidName($name)) { - throw new \InvalidArgumentException(sprintf( + throw new InvalidArgumentException(sprintf( 'The name "%s" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").', $name )); diff --git a/src/Symfony/Component/Form/FormExtensionInterface.php b/src/Symfony/Component/Form/FormExtensionInterface.php index dc3ca46570..a67055b797 100644 --- a/src/Symfony/Component/Form/FormExtensionInterface.php +++ b/src/Symfony/Component/Form/FormExtensionInterface.php @@ -23,7 +23,7 @@ interface FormExtensionInterface * * @return FormTypeInterface The type * - * @throws Exception\FormException if the given type is not supported by this extension + * @throws Exception\InvalidArgumentException if the given type is not supported by this extension */ public function getType($name); diff --git a/src/Symfony/Component/Form/FormFactoryInterface.php b/src/Symfony/Component/Form/FormFactoryInterface.php index 8edfa95e52..31c46b55d7 100644 --- a/src/Symfony/Component/Form/FormFactoryInterface.php +++ b/src/Symfony/Component/Form/FormFactoryInterface.php @@ -27,7 +27,7 @@ interface FormFactoryInterface * * @return FormInterface The form named after the type * - * @throws Exception\FormException if any given option is not applicable to the given type + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ public function create($type = 'form', $data = null, array $options = array()); @@ -43,7 +43,7 @@ interface FormFactoryInterface * * @return FormInterface The form * - * @throws Exception\FormException if any given option is not applicable to the given type + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ public function createNamed($name, $type = 'form', $data = null, array $options = array()); @@ -59,7 +59,7 @@ interface FormFactoryInterface * * @return FormInterface The form named after the property * - * @throws Exception\FormException if any given option is not applicable to the form type + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type */ public function createForProperty($class, $property, $data = null, array $options = array()); @@ -72,7 +72,7 @@ interface FormFactoryInterface * * @return FormBuilderInterface The form builder * - * @throws Exception\FormException if any given option is not applicable to the given type + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ public function createBuilder($type = 'form', $data = null, array $options = array()); @@ -86,7 +86,7 @@ interface FormFactoryInterface * * @return FormBuilderInterface The form builder * - * @throws Exception\FormException if any given option is not applicable to the given type + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type */ public function createNamedBuilder($name, $type = 'form', $data = null, array $options = array()); @@ -103,7 +103,7 @@ interface FormFactoryInterface * * @return FormBuilderInterface The form builder named after the property * - * @throws Exception\FormException if any given option is not applicable to the form type + * @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type */ public function createBuilderForProperty($class, $property, $data = null, array $options = array()); } diff --git a/src/Symfony/Component/Form/FormInterface.php b/src/Symfony/Component/Form/FormInterface.php index 05d95b2282..00512f0833 100644 --- a/src/Symfony/Component/Form/FormInterface.php +++ b/src/Symfony/Component/Form/FormInterface.php @@ -26,7 +26,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable * @return FormInterface The form instance * * @throws Exception\AlreadyBoundException If the form has already been bound. - * @throws Exception\FormException When trying to set a parent for a form with + * @throws Exception\LogicException When trying to set a parent for a form with * an empty name. */ public function setParent(FormInterface $parent = null); @@ -48,7 +48,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable * @return FormInterface The form instance * * @throws Exception\AlreadyBoundException If the form has already been bound. - * @throws Exception\FormException When trying to add a child to a non-compound form. + * @throws Exception\LogicException When trying to add a child to a non-compound form. * @throws Exception\UnexpectedTypeException If $child or $type has an unexpected type. */ public function add($child, $type = null, array $options = array()); @@ -106,7 +106,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable * @return FormInterface The form instance * * @throws Exception\AlreadyBoundException If the form has already been bound. - * @throws Exception\FormException If listeners try to call setData in a cycle. Or if + * @throws Exception\LogicException If listeners try to call setData in a cycle. Or if * the view data does not match the expected type * according to {@link FormConfigInterface::getDataClass}. */ diff --git a/src/Symfony/Component/Form/FormRegistry.php b/src/Symfony/Component/Form/FormRegistry.php index cb2599c932..0267a5657b 100644 --- a/src/Symfony/Component/Form/FormRegistry.php +++ b/src/Symfony/Component/Form/FormRegistry.php @@ -13,7 +13,7 @@ namespace Symfony\Component\Form; use Symfony\Component\Form\Exception\ExceptionInterface; use Symfony\Component\Form\Exception\UnexpectedTypeException; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\InvalidArgumentException; /** * The central registry of the Form component. @@ -86,7 +86,7 @@ class FormRegistry implements FormRegistryInterface } if (!$type) { - throw new Exception(sprintf('Could not load type "%s"', $name)); + throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name)); } $this->resolveAndAddType($type); diff --git a/src/Symfony/Component/Form/FormRegistryInterface.php b/src/Symfony/Component/Form/FormRegistryInterface.php index 4edb9833c8..16cd938441 100644 --- a/src/Symfony/Component/Form/FormRegistryInterface.php +++ b/src/Symfony/Component/Form/FormRegistryInterface.php @@ -27,8 +27,8 @@ interface FormRegistryInterface * * @return ResolvedFormTypeInterface The type * - * @throws Exception\UnexpectedTypeException if the passed name is not a string - * @throws Exception\FormException if the type can not be retrieved from any extension + * @throws Exception\UnexpectedTypeException if the passed name is not a string + * @throws Exception\InvalidArgumentException if the type can not be retrieved from any extension */ public function getType($name); diff --git a/src/Symfony/Component/Form/FormRenderer.php b/src/Symfony/Component/Form/FormRenderer.php index 09b830b43e..09b010563f 100644 --- a/src/Symfony/Component/Form/FormRenderer.php +++ b/src/Symfony/Component/Form/FormRenderer.php @@ -11,7 +11,8 @@ namespace Symfony\Component\Form; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\LogicException; +use Symfony\Component\Form\Exception\BadMethodCallException; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface; /** @@ -76,7 +77,7 @@ class FormRenderer implements FormRendererInterface public function renderCsrfToken($intention) { if (null === $this->csrfProvider) { - throw new \BadMethodCallException('CSRF token can only be generated if a CsrfProviderInterface is injected in the constructor.'); + throw new BadMethodCallException('CSRF token can only be generated if a CsrfProviderInterface is injected in the constructor.'); } return $this->csrfProvider->generateCsrfToken($intention); @@ -90,7 +91,7 @@ class FormRenderer implements FormRendererInterface $resource = $this->engine->getResourceForBlockName($view, $blockName); if (!$resource) { - throw new Exception(sprintf('No block "%s" found while rendering the form.', $blockName)); + throw new LogicException(sprintf('No block "%s" found while rendering the form.', $blockName)); } $viewCacheKey = $view->vars[self::CACHE_KEY_VAR]; @@ -235,7 +236,7 @@ class FormRenderer implements FormRendererInterface // Escape if no resource exists for this block if (!$resource) { - throw new Exception(sprintf( + throw new LogicException(sprintf( 'Unable to render the form as none of the following blocks exist: "%s".', implode('", "', array_reverse($blockNameHierarchy)) )); diff --git a/src/Symfony/Component/Form/FormView.php b/src/Symfony/Component/Form/FormView.php index 8b9528c3b7..1f53ec6a40 100644 --- a/src/Symfony/Component/Form/FormView.php +++ b/src/Symfony/Component/Form/FormView.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Form; +use Symfony\Component\Form\Exception\BadMethodCallException; + /** * @author Bernhard Schussek */ @@ -118,11 +120,11 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable /** * Implements \ArrayAccess. * - * @throws \BadMethodCallException always as setting a child by name is not allowed + * @throws BadMethodCallException always as setting a child by name is not allowed */ public function offsetSet($name, $value) { - throw new \BadMethodCallException('Not supported'); + throw new BadMethodCallException('Not supported'); } /** diff --git a/src/Symfony/Component/Form/Guess/Guess.php b/src/Symfony/Component/Form/Guess/Guess.php index f24407dd73..b33c3d802d 100644 --- a/src/Symfony/Component/Form/Guess/Guess.php +++ b/src/Symfony/Component/Form/Guess/Guess.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Form\Guess; +use Symfony\Component\Form\Exception\InvalidArgumentException; + /** * Base class for guesses made by TypeGuesserInterface implementation * @@ -86,13 +88,13 @@ abstract class Guess * * @param integer $confidence The confidence * - * @throws \InvalidArgumentException if the given value of confidence is unknown + * @throws InvalidArgumentException if the given value of confidence is unknown */ public function __construct($confidence) { if (self::VERY_HIGH_CONFIDENCE !== $confidence && self::HIGH_CONFIDENCE !== $confidence && self::MEDIUM_CONFIDENCE !== $confidence && self::LOW_CONFIDENCE !== $confidence) { - throw new \InvalidArgumentException('The confidence should be one of the constants defined in Guess.'); + throw new InvalidArgumentException('The confidence should be one of the constants defined in Guess.'); } $this->confidence = $confidence; diff --git a/src/Symfony/Component/Form/PreloadedExtension.php b/src/Symfony/Component/Form/PreloadedExtension.php index eac7b0582d..2d3e9efb08 100644 --- a/src/Symfony/Component/Form/PreloadedExtension.php +++ b/src/Symfony/Component/Form/PreloadedExtension.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\InvalidArgumentException; /** * A form extension with preloaded types, type exceptions and type guessers. @@ -55,7 +55,7 @@ class PreloadedExtension implements FormExtensionInterface public function getType($name) { if (!isset($this->types[$name])) { - throw new Exception(sprintf('The type "%s" can not be loaded by this extension', $name)); + throw new InvalidArgumentException(sprintf('The type "%s" can not be loaded by this extension', $name)); } return $this->types[$name]; diff --git a/src/Symfony/Component/Form/ResolvedFormType.php b/src/Symfony/Component/Form/ResolvedFormType.php index e48ea5e64d..47d43553cd 100644 --- a/src/Symfony/Component/Form/ResolvedFormType.php +++ b/src/Symfony/Component/Form/ResolvedFormType.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Form; -use Symfony\Component\Form\Exception\Exception; +use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -46,7 +46,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface public function __construct(FormTypeInterface $innerType, array $typeExtensions = array(), ResolvedFormTypeInterface $parent = null) { if (!preg_match('/^[a-z0-9_]*$/i', $innerType->getName())) { - throw new Exception(sprintf( + throw new InvalidArgumentException(sprintf( 'The "%s" form type name ("%s") is not valid. Names must only contain letters, numbers, and "_".', get_class($innerType), $innerType->getName() diff --git a/src/Symfony/Component/Form/ResolvedFormTypeFactoryInterface.php b/src/Symfony/Component/Form/ResolvedFormTypeFactoryInterface.php index fb2aa4acce..f0ec23308f 100644 --- a/src/Symfony/Component/Form/ResolvedFormTypeFactoryInterface.php +++ b/src/Symfony/Component/Form/ResolvedFormTypeFactoryInterface.php @@ -31,8 +31,8 @@ interface ResolvedFormTypeFactoryInterface * * @return ResolvedFormTypeInterface * - * @throws Exception\UnexpectedTypeException if the types parent {@link FormTypeInterface::getParent()} is not a string - * @throws Exception\FormException if the types parent can not be retrieved from any extension + * @throws Exception\UnexpectedTypeException if the types parent {@link FormTypeInterface::getParent()} is not a string + * @throws Exception\InvalidArgumentException if the types parent can not be retrieved from any extension */ public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php index 6a6a48c7d6..bcd309e050 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php @@ -82,7 +82,7 @@ class LazyChoiceListTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Symfony\Component\Form\Exception\Exception + * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException */ public function testLoadChoiceListShouldReturnChoiceList() { diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php index b7487377e6..69c5aa0fcb 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php @@ -196,7 +196,7 @@ class ObjectChoiceListTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Symfony\Component\Form\Exception\Exception + * @expectedException \Symfony\Component\Form\Exception\StringCastException */ public function testInitArrayThrowsExceptionIfToStringNotFound() { diff --git a/src/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php b/src/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php index 37c2771385..a5a31248f5 100644 --- a/src/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php +++ b/src/Symfony/Component/Form/Tests/Fixtures/FixedDataTransformer.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Form\Tests\Fixtures; use Symfony\Component\Form\DataTransformerInterface; +use Symfony\Component\Form\Exception\RuntimeException; class FixedDataTransformer implements DataTransformerInterface { @@ -25,7 +26,7 @@ class FixedDataTransformer implements DataTransformerInterface public function transform($value) { if (!array_key_exists($value, $this->mapping)) { - throw new \RuntimeException(sprintf('No mapping for value "%s"', $value)); + throw new RuntimeException(sprintf('No mapping for value "%s"', $value)); } return $this->mapping[$value]; @@ -36,7 +37,7 @@ class FixedDataTransformer implements DataTransformerInterface $result = array_search($value, $this->mapping, true); if ($result === false) { - throw new \RuntimeException(sprintf('No reverse mapping for value "%s"', $value)); + throw new RuntimeException(sprintf('No reverse mapping for value "%s"', $value)); } return $result; diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index 4f8cf05da8..e076c97e78 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -162,7 +162,7 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase public function testGetUnknown() { - $this->setExpectedException('Symfony\Component\Form\Exception\Exception', 'The child with the name "foo" does not exist.'); + $this->setExpectedException('Symfony\Component\Form\Exception\InvalidArgumentException', 'The child with the name "foo" does not exist.'); $this->builder->get('foo'); } diff --git a/src/Symfony/Component/Form/Tests/FormConfigTest.php b/src/Symfony/Component/Form/Tests/FormConfigTest.php index 4337a2ab68..90c882f1f1 100644 --- a/src/Symfony/Component/Form/Tests/FormConfigTest.php +++ b/src/Symfony/Component/Form/Tests/FormConfigTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Tests; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\FormConfigBuilder; +use Symfony\Component\Form\Exception\InvalidArgumentException; /** * @author Bernhard Schussek @@ -82,7 +83,7 @@ class FormConfigTest extends \PHPUnit_Framework_TestCase if ($accepted) { throw $e; } - } catch (\InvalidArgumentException $e) { + } catch (InvalidArgumentException $e) { // if the value was not accepted, but should be, rethrow exception if ($accepted) { throw $e; @@ -131,7 +132,7 @@ class FormConfigTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Symfony\Component\Form\Exception\FormException + * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException */ public function testSetMethodDoesNotAllowOtherValues() { diff --git a/src/Symfony/Component/Form/Tests/FormRegistryTest.php b/src/Symfony/Component/Form/Tests/FormRegistryTest.php index d29631dcc1..0c8bb6b441 100644 --- a/src/Symfony/Component/Form/Tests/FormRegistryTest.php +++ b/src/Symfony/Component/Form/Tests/FormRegistryTest.php @@ -173,7 +173,7 @@ class FormRegistryTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Symfony\Component\Form\Exception\Exception + * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException */ public function testGetTypeThrowsExceptionIfParentNotFound() { @@ -185,7 +185,7 @@ class FormRegistryTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \Symfony\Component\Form\Exception\Exception + * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException */ public function testGetTypeThrowsExceptionIfTypeNotFound() { diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index 65f3ee2949..01c0a947d0 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -718,7 +718,7 @@ class SimpleFormTest extends AbstractFormTest } /** - * @expectedException \Symfony\Component\Form\Exception\Exception + * @expectedException \Symfony\Component\Form\Exception\LogicException * @expectedExceptionMessage A form with an empty name cannot have a parent form. */ public function testFormCannotHaveEmptyNameNotInRootLevel() @@ -800,7 +800,7 @@ class SimpleFormTest extends AbstractFormTest } /** - * @expectedException \Symfony\Component\Form\Exception\Exception + * @expectedException \Symfony\Component\Form\Exception\LogicException */ public function testViewDataMustNotBeObjectIfDataClassIsNull() { @@ -830,7 +830,7 @@ class SimpleFormTest extends AbstractFormTest } /** - * @expectedException \Symfony\Component\Form\Exception\Exception + * @expectedException \Symfony\Component\Form\Exception\LogicException */ public function testViewDataMustBeObjectIfDataClassIsSet() { @@ -917,7 +917,7 @@ class SimpleFormTest extends AbstractFormTest } /** - * @expectedException \Symfony\Component\Form\Exception\FormException + * @expectedException \Symfony\Component\Form\Exception\RuntimeException */ public function testInheritDataDisallowsSetData() { @@ -929,7 +929,7 @@ class SimpleFormTest extends AbstractFormTest } /** - * @expectedException \Symfony\Component\Form\Exception\FormException + * @expectedException \Symfony\Component\Form\Exception\RuntimeException */ public function testGetDataRequiresParentToBeSetIfInheritData() { @@ -941,7 +941,7 @@ class SimpleFormTest extends AbstractFormTest } /** - * @expectedException \Symfony\Component\Form\Exception\FormException + * @expectedException \Symfony\Component\Form\Exception\RuntimeException */ public function testGetNormDataRequiresParentToBeSetIfInheritData() { @@ -953,7 +953,7 @@ class SimpleFormTest extends AbstractFormTest } /** - * @expectedException \Symfony\Component\Form\Exception\FormException + * @expectedException \Symfony\Component\Form\Exception\RuntimeException */ public function testGetViewDataRequiresParentToBeSetIfInheritData() {