[Form] Make exception handling consistent with other components

This commit is contained in:
Alexander Kotynia 2013-04-15 23:11:02 +03:00
parent d6376c1b49
commit bf9382e6cd
45 changed files with 178 additions and 212 deletions

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form; 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\Form\Exception\UnexpectedTypeException;
/** /**
@ -53,7 +53,7 @@ abstract class AbstractExtension implements FormExtensionInterface
} }
if (!isset($this->types[$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]; return $this->types[$name];

View File

@ -65,11 +65,11 @@ class Button implements \IteratorAggregate, FormInterface
* *
* @param mixed $offset * @param mixed $offset
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function offsetGet($offset) 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 $offset
* @param mixed $value * @param mixed $value
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function offsetSet($offset, $value) 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 * @param mixed $offset
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function offsetUnset($offset) 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 null $type
* @param array $options * @param array $options
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function add($child, $type = null, array $options = array()) 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 * @param string $name
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function get($name) 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 * @param string $name
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function remove($name) 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 * @param string $modelData
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setData($modelData) 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 * @param FormError $error
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function addError(FormError $error) public function addError(FormError $error)
{ {
throw new \BadMethodCallException('Buttons cannot have errors.'); throw new BadMethodCallException('Buttons cannot have errors.');
} }
/** /**

View File

@ -12,8 +12,8 @@
namespace Symfony\Component\Form; namespace Symfony\Component\Form;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Exception\InvalidArgumentException; use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\Form\Exception\BadMethodCallException;
/** /**
* A builder for {@link Button} instances. * A builder for {@link Button} instances.
@ -58,7 +58,7 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
* @param string $name The name of the button. * @param string $name The name of the button.
* @param array $options The button's options. * @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) public function __construct($name, array $options)
{ {
@ -79,11 +79,11 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
* @param string|FormTypeInterface $type * @param string|FormTypeInterface $type
* @param array $options * @param array $options
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function add($child, $type = null, array $options = array()) 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 string|FormTypeInterface $type
* @param array $options * @param array $options
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function create($name, $type = null, array $options = array()) 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 * @param string $name
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function get($name) 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 * @param string $name
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function remove($name) 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 callable $listener
* @param integer $priority * @param integer $priority
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function addEventListener($eventName, $listener, $priority = 0) 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 * @param EventSubscriberInterface $subscriber
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function addEventSubscriber(EventSubscriberInterface $subscriber) 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 DataTransformerInterface $viewTransformer
* @param Boolean $forcePrepend * @param Boolean $forcePrepend
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function addViewTransformer(DataTransformerInterface $viewTransformer, $forcePrepend = false) 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. * This method should not be invoked.
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function resetViewTransformers() 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 DataTransformerInterface $modelTransformer
* @param Boolean $forceAppend * @param Boolean $forceAppend
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function addModelTransformer(DataTransformerInterface $modelTransformer, $forceAppend = false) 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. * This method should not be invoked.
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function resetModelTransformers() 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 * @param DataMapperInterface $dataMapper
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setDataMapper(DataMapperInterface $dataMapper = null) 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 * @param mixed $emptyData
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setEmptyData($emptyData) 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 * @param Boolean $errorBubbling
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setErrorBubbling($errorBubbling) 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 * @param Boolean $required
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setRequired($required) 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 * @param null $propertyPath
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setPropertyPath($propertyPath) 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 * @param Boolean $mapped
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setMapped($mapped) 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 * @param Boolean $byReference
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setByReference($byReference) 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 * @param Boolean $virtual
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setVirtual($virtual) 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 * @param Boolean $compound
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setCompound($compound) 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 * @param array $data
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setData($data) 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 * @param Boolean $locked
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setDataLocked($locked) 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 * @return void
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setFormFactory(FormFactoryInterface $formFactory) 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 * @param string $action
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setAction($action) 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 * @param string $method
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setMethod($method) 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 * @param FormProcessorInterface $formProcessor
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setFormProcessor(FormProcessorInterface $formProcessor) 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 * @param Boolean $inheritData
* *
* @throws \BadMethodCallException * @throws BadMethodCallException
*/ */
public function setInheritData($inheritData) public function setInheritData($inheritData)
{ {
throw new \BadMethodCallException('Buttons do not support data inheritance.'); throw new BadMethodCallException('Buttons do not support data inheritance.');
} }
/** /**

View File

@ -15,6 +15,9 @@ CHANGELOG
* deprecated VirtualFormAwareIterator in favor of InheritDataAwareIterator * deprecated VirtualFormAwareIterator in favor of InheritDataAwareIterator
* [BC BREAK] removed the "array" type hint from DataMapperInterface * [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() * 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 2.2.0
----- -----

View File

@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception; namespace Symfony\Component\Form\Exception;
class AlreadyBoundException extends Exception class AlreadyBoundException extends LogicException
{ {
} }

View File

@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception; namespace Symfony\Component\Form\Exception;
class ErrorMappingException extends Exception class ErrorMappingException extends RuntimeException
{ {
} }

View File

@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception; namespace Symfony\Component\Form\Exception;
class InvalidConfigurationException extends Exception class InvalidConfigurationException extends InvalidArgumentException
{ {
} }

View File

@ -12,10 +12,10 @@
namespace Symfony\Component\Form\Exception; namespace Symfony\Component\Form\Exception;
/** /**
* Thrown when a form could not be constructed by a FormFactory * Base LogicException for Form component.
* *
* @author Bernhard Schussek <bschussek@gmail.com> * @author Alexander Kotynia <aleksander.kot@gmail.com>
*/ */
class CreationException extends Exception class LogicException extends \LogicException implements ExceptionInterface
{ {
} }

View File

@ -1,16 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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
{
}

View File

@ -1,16 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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
{
}

View File

@ -12,10 +12,10 @@
namespace Symfony\Component\Form\Exception; namespace Symfony\Component\Form\Exception;
/** /**
* Thrown when a form type is configured incorrectly * Base OutOfBoundsException for Form component.
* *
* @author Bernhard Schussek <bschussek@gmail.com> * @author Alexander Kotynia <aleksander.kot@gmail.com>
*/ */
class TypeDefinitionException extends Exception class OutOfBoundsException extends \OutOfBoundsException implements ExceptionInterface
{ {
} }

View File

@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception; namespace Symfony\Component\Form\Exception;
class StringCastException extends Exception class StringCastException extends RuntimeException
{ {
} }

View File

@ -16,6 +16,6 @@ namespace Symfony\Component\Form\Exception;
* *
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*/ */
class TransformationFailedException extends \RuntimeException implements ExceptionInterface class TransformationFailedException extends RuntimeException
{ {
} }

View File

@ -1,16 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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
{
}

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Exception; namespace Symfony\Component\Form\Exception;
class UnexpectedTypeException extends Exception class UnexpectedTypeException extends InvalidArgumentException
{ {
public function __construct($value, $expectedType) public function __construct($value, $expectedType)
{ {

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\FormConfigBuilder; use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\InvalidConfigurationException; use Symfony\Component\Form\Exception\InvalidConfigurationException;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\Form\Extension\Core\View\ChoiceView; 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 $labels The labels corresponding to the choices.
* @param array $preferredChoices The preferred 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. * @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) 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 // Add choices to the nested buckets
foreach ($choices as $group => $choice) { foreach ($choices as $group => $choice) {
if (!array_key_exists($group, $labels)) { 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)) { if (is_array($choice)) {

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Extension\Core\ChoiceList; 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 * A choice list that is loaded lazily
@ -141,7 +141,7 @@ abstract class LazyChoiceList implements ChoiceListInterface
$choiceList = $this->loadChoiceList(); $choiceList = $this->loadChoiceList();
if (!$choiceList instanceof ChoiceListInterface) { 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; $this->choiceList = $choiceList;

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\ChoiceList; namespace Symfony\Component\Form\Extension\Core\ChoiceList;
use Symfony\Component\Form\Exception\StringCastException; use Symfony\Component\Form\Exception\StringCastException;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException; use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccess;
@ -103,7 +104,7 @@ class ObjectChoiceList extends ChoiceList
* @param array $labels Ignored. * @param array $labels Ignored.
* @param array $preferredChoices The choices to display with priority. * @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. * the "groupPath" option at the same time.
*/ */
protected function initialize($choices, array $labels, array $preferredChoices) protected function initialize($choices, array $labels, array $preferredChoices)
@ -113,7 +114,7 @@ class ObjectChoiceList extends ChoiceList
foreach ($choices as $i => $choice) { foreach ($choices as $i => $choice) {
if (is_array($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 { try {

View File

@ -15,7 +15,7 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView; 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\ChoiceList\SimpleChoiceList;
use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener; use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener;
use Symfony\Component\Form\Extension\Core\EventListener\FixCheckboxInputListener; use Symfony\Component\Form\Extension\Core\EventListener\FixCheckboxInputListener;
@ -41,7 +41,7 @@ class ChoiceType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options) public function buildForm(FormBuilderInterface $builder, array $options)
{ {
if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) { 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']) { if ($options['expanded']) {

View File

@ -16,7 +16,7 @@ use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView; use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener; use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper; 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\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\PropertyAccess\PropertyAccess;
@ -74,7 +74,7 @@ class FormType extends BaseType
if ($view->parent) { if ($view->parent) {
if ('' === $name) { 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. // Complex fields are read-only if they themselves or their parents are.

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\DependencyInjection;
use Symfony\Component\Form\FormExtensionInterface; use Symfony\Component\Form\FormExtensionInterface;
use Symfony\Component\Form\FormTypeGuesserChain; use Symfony\Component\Form\FormTypeGuesserChain;
use Symfony\Component\Form\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
class DependencyInjectionExtension implements FormExtensionInterface class DependencyInjectionExtension implements FormExtensionInterface
@ -40,13 +41,13 @@ class DependencyInjectionExtension implements FormExtensionInterface
public function getType($name) public function getType($name)
{ {
if (!isset($this->typeServiceIds[$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]); $type = $this->container->get($this->typeServiceIds[$name]);
if ($type->getName() !== $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"', sprintf('The type name specified for the service "%s" does not match the actual name. Expected "%s", given "%s"',
$this->typeServiceIds[$name], $this->typeServiceIds[$name],
$name, $name,

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form\Extension\HttpFoundation\EventListener;
use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent; 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\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -80,7 +80,7 @@ class BindRequestListener implements EventSubscriberInterface
break; break;
default: default:
throw new Exception(sprintf( throw new LogicException(sprintf(
'The request method "%s" is not supported', 'The request method "%s" is not supported',
$request->getMethod() $request->getMethod()
)); ));

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Form\Extension\Validator\ViolationMapper; namespace Symfony\Component\Form\Extension\Validator\ViolationMapper;
use Symfony\Component\Form\Exception\OutOfBoundsException;
use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\PropertyAccess\PropertyPathInterface; use Symfony\Component\PropertyAccess\PropertyPathInterface;
@ -155,7 +156,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function getElement($index) public function getElement($index)
{ {
if (!isset($this->elements[$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]; return $this->elements[$index];
@ -167,7 +168,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function isProperty($index) public function isProperty($index)
{ {
if (!isset($this->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]; return !$this->isIndex[$index];
@ -179,7 +180,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function isIndex($index) public function isIndex($index)
{ {
if (!isset($this->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]; return $this->isIndex[$index];
@ -201,12 +202,12 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
* *
* @return Boolean Whether the element maps to a form. * @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) public function mapsForm($index)
{ {
if (!isset($this->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]; return $this->mapsForm[$index];

View File

@ -11,12 +11,12 @@
namespace Symfony\Component\Form; 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\RuntimeException;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\AlreadyBoundException; use Symfony\Component\Form\Exception\AlreadyBoundException;
use Symfony\Component\Form\Exception\TransformationFailedException; 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\FormUtil;
use Symfony\Component\Form\Util\InheritDataAwareIterator; use Symfony\Component\Form\Util\InheritDataAwareIterator;
use Symfony\Component\PropertyAccess\PropertyPath; use Symfony\Component\PropertyAccess\PropertyPath;
@ -146,7 +146,7 @@ class Form implements \IteratorAggregate, FormInterface
* *
* @param FormConfigInterface $config The form configuration. * @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) 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 // `setData` and `add` will not lead to the correct population of
// the child forms. // the child forms.
if ($config->getCompound() && !$config->getDataMapper()) { 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 // 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()) { 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; $this->parent = $parent;
@ -340,7 +340,7 @@ class Form implements \IteratorAggregate, FormInterface
if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) { if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) {
$expectedType = 'scalar, array or an instance of \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.', ' . 'The form\'s view data is expected to be of type '.$expectedType.', ' .
'but is '.$actualType.'. You ' . 'but is '.$actualType.'. You ' .
'can avoid this error by setting the "data_class" option to ' . '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) { 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 ' . 'The form\'s view data is expected to be an instance of class ' .
$dataClass.', but is '. $actualType.'. You can avoid this error ' . $dataClass.', but is '. $actualType.'. You can avoid this error ' .
'by setting the "data_class" option to null or by adding a view ' . '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()) { 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 // Obtain the view data
@ -815,7 +815,7 @@ class Form implements \IteratorAggregate, FormInterface
return $this->children[$name]; 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. * @param FormInterface $child The child to be added.
* *
* @throws AlreadyBoundException If the form has already been bound. * @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() * @see self::add()
*/ */

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Form; namespace Symfony\Component\Form;
use Symfony\Component\Form\Exception\BadMethodCallException; 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\Form\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -126,7 +126,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
return $this->children[$name]; 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));
} }
/** /**

View File

@ -49,7 +49,7 @@ interface FormBuilderInterface extends \Traversable, \Countable, FormConfigBuild
* *
* @return FormBuilderInterface The builder for the child * @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); public function get($name);

View File

@ -185,7 +185,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
* @param EventDispatcherInterface $dispatcher The event dispatcher * @param EventDispatcherInterface $dispatcher The event dispatcher
* @param array $options The form options * @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. * the name contains invalid characters.
*/ */
public function __construct($name, $dataClass, EventDispatcherInterface $dispatcher, array $options = array()) public function __construct($name, $dataClass, EventDispatcherInterface $dispatcher, array $options = array())
@ -193,7 +193,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
self::validateName($name); self::validateName($name);
if (null !== $dataClass && !class_exists($dataClass)) { 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; $this->name = (string) $name;
@ -865,7 +865,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
* @param string|integer $name The tested form name. * @param string|integer $name The tested form name.
* *
* @throws UnexpectedTypeException If the name is not a string or an integer. * @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) public static function validateName($name)
{ {
@ -874,7 +874,7 @@ class FormConfigBuilder implements FormConfigBuilderInterface
} }
if (!self::isValidName($name)) { 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 (":").', '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 $name
)); ));

View File

@ -23,7 +23,7 @@ interface FormExtensionInterface
* *
* @return FormTypeInterface The type * @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); public function getType($name);

View File

@ -27,7 +27,7 @@ interface FormFactoryInterface
* *
* @return FormInterface The form named after the type * @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()); public function create($type = 'form', $data = null, array $options = array());
@ -43,7 +43,7 @@ interface FormFactoryInterface
* *
* @return FormInterface The form * @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()); 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 * @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()); public function createForProperty($class, $property, $data = null, array $options = array());
@ -72,7 +72,7 @@ interface FormFactoryInterface
* *
* @return FormBuilderInterface The form builder * @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()); public function createBuilder($type = 'form', $data = null, array $options = array());
@ -86,7 +86,7 @@ interface FormFactoryInterface
* *
* @return FormBuilderInterface The form builder * @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()); 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 * @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()); public function createBuilderForProperty($class, $property, $data = null, array $options = array());
} }

View File

@ -26,7 +26,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
* @return FormInterface The form instance * @return FormInterface The form instance
* *
* @throws Exception\AlreadyBoundException If the form has already been bound. * @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. * an empty name.
*/ */
public function setParent(FormInterface $parent = null); public function setParent(FormInterface $parent = null);
@ -48,7 +48,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
* @return FormInterface The form instance * @return FormInterface The form instance
* *
* @throws Exception\AlreadyBoundException If the form has already been bound. * @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. * @throws Exception\UnexpectedTypeException If $child or $type has an unexpected type.
*/ */
public function add($child, $type = null, array $options = array()); public function add($child, $type = null, array $options = array());
@ -106,7 +106,7 @@ interface FormInterface extends \ArrayAccess, \Traversable, \Countable
* @return FormInterface The form instance * @return FormInterface The form instance
* *
* @throws Exception\AlreadyBoundException If the form has already been bound. * @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 * the view data does not match the expected type
* according to {@link FormConfigInterface::getDataClass}. * according to {@link FormConfigInterface::getDataClass}.
*/ */

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Form;
use Symfony\Component\Form\Exception\ExceptionInterface; use Symfony\Component\Form\Exception\ExceptionInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException; 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. * The central registry of the Form component.
@ -86,7 +86,7 @@ class FormRegistry implements FormRegistryInterface
} }
if (!$type) { 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); $this->resolveAndAddType($type);

View File

@ -27,8 +27,8 @@ interface FormRegistryInterface
* *
* @return ResolvedFormTypeInterface The type * @return ResolvedFormTypeInterface The type
* *
* @throws Exception\UnexpectedTypeException if the passed name is not a string * @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\InvalidArgumentException if the type can not be retrieved from any extension
*/ */
public function getType($name); public function getType($name);

View File

@ -11,7 +11,8 @@
namespace Symfony\Component\Form; 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; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\CsrfProviderInterface;
/** /**
@ -76,7 +77,7 @@ class FormRenderer implements FormRendererInterface
public function renderCsrfToken($intention) public function renderCsrfToken($intention)
{ {
if (null === $this->csrfProvider) { 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); return $this->csrfProvider->generateCsrfToken($intention);
@ -90,7 +91,7 @@ class FormRenderer implements FormRendererInterface
$resource = $this->engine->getResourceForBlockName($view, $blockName); $resource = $this->engine->getResourceForBlockName($view, $blockName);
if (!$resource) { 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]; $viewCacheKey = $view->vars[self::CACHE_KEY_VAR];
@ -235,7 +236,7 @@ class FormRenderer implements FormRendererInterface
// Escape if no resource exists for this block // Escape if no resource exists for this block
if (!$resource) { if (!$resource) {
throw new Exception(sprintf( throw new LogicException(sprintf(
'Unable to render the form as none of the following blocks exist: "%s".', 'Unable to render the form as none of the following blocks exist: "%s".',
implode('", "', array_reverse($blockNameHierarchy)) implode('", "', array_reverse($blockNameHierarchy))
)); ));

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Form; namespace Symfony\Component\Form;
use Symfony\Component\Form\Exception\BadMethodCallException;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
*/ */
@ -118,11 +120,11 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
/** /**
* Implements \ArrayAccess. * 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) public function offsetSet($name, $value)
{ {
throw new \BadMethodCallException('Not supported'); throw new BadMethodCallException('Not supported');
} }
/** /**

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Form\Guess; namespace Symfony\Component\Form\Guess;
use Symfony\Component\Form\Exception\InvalidArgumentException;
/** /**
* Base class for guesses made by TypeGuesserInterface implementation * Base class for guesses made by TypeGuesserInterface implementation
* *
@ -86,13 +88,13 @@ abstract class Guess
* *
* @param integer $confidence The confidence * @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) public function __construct($confidence)
{ {
if (self::VERY_HIGH_CONFIDENCE !== $confidence && self::HIGH_CONFIDENCE !== $confidence && if (self::VERY_HIGH_CONFIDENCE !== $confidence && self::HIGH_CONFIDENCE !== $confidence &&
self::MEDIUM_CONFIDENCE !== $confidence && self::LOW_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; $this->confidence = $confidence;

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form; 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. * A form extension with preloaded types, type exceptions and type guessers.
@ -55,7 +55,7 @@ class PreloadedExtension implements FormExtensionInterface
public function getType($name) public function getType($name)
{ {
if (!isset($this->types[$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]; return $this->types[$name];

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Form; 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\Form\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -46,7 +46,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
public function __construct(FormTypeInterface $innerType, array $typeExtensions = array(), ResolvedFormTypeInterface $parent = null) public function __construct(FormTypeInterface $innerType, array $typeExtensions = array(), ResolvedFormTypeInterface $parent = null)
{ {
if (!preg_match('/^[a-z0-9_]*$/i', $innerType->getName())) { 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 "_".', 'The "%s" form type name ("%s") is not valid. Names must only contain letters, numbers, and "_".',
get_class($innerType), get_class($innerType),
$innerType->getName() $innerType->getName()

View File

@ -31,8 +31,8 @@ interface ResolvedFormTypeFactoryInterface
* *
* @return ResolvedFormTypeInterface * @return ResolvedFormTypeInterface
* *
* @throws Exception\UnexpectedTypeException if the types parent {@link FormTypeInterface::getParent()} is not a string * @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\InvalidArgumentException if the types parent can not be retrieved from any extension
*/ */
public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null); public function createResolvedType(FormTypeInterface $type, array $typeExtensions, ResolvedFormTypeInterface $parent = null);
} }

View File

@ -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() public function testLoadChoiceListShouldReturnChoiceList()
{ {

View File

@ -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() public function testInitArrayThrowsExceptionIfToStringNotFound()
{ {

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Tests\Fixtures; namespace Symfony\Component\Form\Tests\Fixtures;
use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\RuntimeException;
class FixedDataTransformer implements DataTransformerInterface class FixedDataTransformer implements DataTransformerInterface
{ {
@ -25,7 +26,7 @@ class FixedDataTransformer implements DataTransformerInterface
public function transform($value) public function transform($value)
{ {
if (!array_key_exists($value, $this->mapping)) { 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]; return $this->mapping[$value];
@ -36,7 +37,7 @@ class FixedDataTransformer implements DataTransformerInterface
$result = array_search($value, $this->mapping, true); $result = array_search($value, $this->mapping, true);
if ($result === false) { 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; return $result;

View File

@ -162,7 +162,7 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
public function testGetUnknown() 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'); $this->builder->get('foo');
} }

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\FormConfigBuilder; use Symfony\Component\Form\FormConfigBuilder;
use Symfony\Component\Form\Exception\InvalidArgumentException;
/** /**
* @author Bernhard Schussek <bschussek@gmail.com> * @author Bernhard Schussek <bschussek@gmail.com>
@ -82,7 +83,7 @@ class FormConfigTest extends \PHPUnit_Framework_TestCase
if ($accepted) { if ($accepted) {
throw $e; throw $e;
} }
} catch (\InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
// if the value was not accepted, but should be, rethrow exception // if the value was not accepted, but should be, rethrow exception
if ($accepted) { if ($accepted) {
throw $e; 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() public function testSetMethodDoesNotAllowOtherValues()
{ {

View File

@ -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() 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() public function testGetTypeThrowsExceptionIfTypeNotFound()
{ {

View File

@ -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. * @expectedExceptionMessage A form with an empty name cannot have a parent form.
*/ */
public function testFormCannotHaveEmptyNameNotInRootLevel() 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() 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() 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() 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() 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() 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() public function testGetViewDataRequiresParentToBeSetIfInheritData()
{ {