Permalink
Browse files

[Form] Introduced base ExceptionInterface

  • Loading branch information...
1 parent af76f44 commit 0d87430a59f53ff8b31bd5769defaed6a96a795c @webmozart webmozart committed Jan 5, 2013
Showing with 154 additions and 97 deletions.
  1. +2 −2 AbstractExtension.php
  2. +1 −0 CHANGELOG.md
  3. +1 −1 Exception/AlreadyBoundException.php
  4. +1 −1 Exception/CreationException.php
  5. +1 −1 Exception/ErrorMappingException.php
  6. +26 −0 Exception/Exception.php
  7. +21 −0 Exception/ExceptionInterface.php
  8. +9 −1 Exception/FormException.php
  9. +1 −1 Exception/InvalidConfigurationException.php
  10. +1 −1 Exception/InvalidPropertyException.php
  11. +1 −1 Exception/InvalidPropertyPathException.php
  12. +1 −1 Exception/NotInitializedException.php
  13. +1 −1 Exception/NotValidException.php
  14. +1 −1 Exception/PropertyAccessDeniedException.php
  15. +1 −1 Exception/StringCastException.php
  16. +2 −2 Exception/TransformationFailedException.php
  17. +1 −1 Exception/TypeDefinitionException.php
  18. +1 −1 Exception/TypeLoaderException.php
  19. +1 −1 Exception/UnexpectedTypeException.php
  20. +2 −2 Extension/Core/ChoiceList/LazyChoiceList.php
  21. +2 −2 Extension/Core/Type/ChoiceType.php
  22. +2 −2 Extension/Core/Type/FormType.php
  23. +2 −2 Extension/HttpFoundation/EventListener/BindRequestListener.php
  24. +7 −7 Form.php
  25. +6 −6 FormBuilder.php
  26. +36 −36 FormConfigBuilder.php
  27. +4 −3 FormRegistry.php
  28. +4 −4 FormRenderer.php
  29. +2 −2 PreloadedExtension.php
  30. +2 −2 ResolvedFormType.php
  31. +1 −1 Tests/Extension/Core/ChoiceList/LazyChoiceListTest.php
  32. +1 −1 Tests/Extension/Core/ChoiceList/ObjectChoiceListTest.php
  33. +1 −1 Tests/Extension/Core/Type/ChoiceTypeTest.php
  34. +1 −1 Tests/FormBuilderTest.php
  35. +2 −2 Tests/FormRegistryTest.php
  36. +4 −4 Tests/SimpleFormTest.php
  37. +1 −1 Tests/Util/PropertyPathCollectionTest.php
View
@@ -11,7 +11,7 @@
namespace Symfony\Component\Form;
-use Symfony\Component\Form\Exception\FormException;
+use Symfony\Component\Form\Exception\Exception;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
@@ -53,7 +53,7 @@ public function getType($name)
}
if (!isset($this->types[$name])) {
- throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
+ throw new Exception(sprintf('The type "%s" can not be loaded by this extension', $name));
}
return $this->types[$name];
View
@@ -9,6 +9,7 @@ CHANGELOG
* FormInterface::add() now accepts a FormInterface instance OR a field's name, type and options
* removed special characters between the choice or text fields of DateType unless
the option "format" is set to a custom value
+ * deprecated FormException and introduced ExceptionInterface instead
2.1.0
-----
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class AlreadyBoundException extends FormException
+class AlreadyBoundException extends Exception
{
}
@@ -16,6 +16,6 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
-class CreationException extends FormException
+class CreationException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class ErrorMappingException extends FormException
+class ErrorMappingException extends Exception
{
}
View
@@ -0,0 +1,26 @@
+<?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;
+
+/**
+ * Base exception class.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ *
+ * @deprecated This class is a replacement for when class FormException was
+ * used previously. It should not be used and will be removed.
+ * Occurrences of this class should be replaced by more specialized
+ * exception classes, preferably derived from SPL exceptions.
+ */
+class Exception extends \Exception implements ExceptionInterface
+{
+}
@@ -0,0 +1,21 @@
+<?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;
+
+/**
+ * Base ExceptionInterface for the Form component.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ */
+interface ExceptionInterface extends FormException
+{
+}
@@ -11,6 +11,14 @@
namespace Symfony\Component\Form\Exception;
-class FormException extends \Exception
+/**
+ * Alias of {@link ExceptionInterface}.
+ *
+ * @author Bernhard Schussek <bschussek@gmail.com>
+ *
+ * @deprecated This interface was deprecated and will be removed in Symfony 2.3.
+ * You should code against {@link ExceptionInterface} instead.
+ */
+interface FormException
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class InvalidConfigurationException extends FormException
+class InvalidConfigurationException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class InvalidPropertyException extends FormException
+class InvalidPropertyException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class InvalidPropertyPathException extends FormException
+class InvalidPropertyPathException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class NotInitializedException extends FormException
+class NotInitializedException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class NotValidException extends FormException
+class NotValidException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class PropertyAccessDeniedException extends FormException
+class PropertyAccessDeniedException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class StringCastException extends FormException
+class StringCastException extends Exception
{
}
@@ -14,8 +14,8 @@
/**
* Indicates a value transformation error.
*
- * @author Bernhard Schussek <bschussek@gmail.com>
+ * @author Bernhard Schussek <bschussek@gmail.com>
*/
-class TransformationFailedException extends \RuntimeException
+class TransformationFailedException extends \RuntimeException implements ExceptionInterface
{
}
@@ -16,6 +16,6 @@
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
-class TypeDefinitionException extends FormException
+class TypeDefinitionException extends Exception
{
}
@@ -11,6 +11,6 @@
namespace Symfony\Component\Form\Exception;
-class TypeLoaderException extends FormException
+class TypeLoaderException extends Exception
{
}
@@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Exception;
-class UnexpectedTypeException extends FormException
+class UnexpectedTypeException extends Exception
{
public function __construct($value, $expectedType)
{
@@ -11,7 +11,7 @@
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
-use Symfony\Component\Form\Exception\FormException;
+use Symfony\Component\Form\Exception\Exception;
/**
* A choice list that is loaded lazily
@@ -141,7 +141,7 @@ private function load()
$choiceList = $this->loadChoiceList();
if (!$choiceList instanceof ChoiceListInterface) {
- throw new FormException('loadChoiceList() should return a ChoiceListInterface instance. Got ' . gettype($choiceList));
+ throw new Exception('loadChoiceList() should return a ChoiceListInterface instance. Got ' . gettype($choiceList));
}
$this->choiceList = $choiceList;
@@ -15,7 +15,7 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
-use Symfony\Component\Form\Exception\FormException;
+use Symfony\Component\Form\Exception\Exception;
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 FormException('Either the option "choices" or "choice_list" must be set.');
+ throw new Exception('Either the option "choices" or "choice_list" must be set.');
}
if ($options['expanded']) {
@@ -17,7 +17,7 @@
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\FormException;
+use Symfony\Component\Form\Exception\Exception;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@@ -61,7 +61,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
if ($view->parent) {
if ('' === $name) {
- throw new FormException('Form node with empty name can be used only as root form node.');
+ throw new Exception('Form node with empty name can be used only as root form node.');
}
if ('' !== ($parentFullName = $view->parent->vars['full_name'])) {
@@ -13,7 +13,7 @@
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
-use Symfony\Component\Form\Exception\FormException;
+use Symfony\Component\Form\Exception\Exception;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -74,7 +74,7 @@ public function preBind(FormEvent $event)
break;
default:
- throw new FormException(sprintf(
+ throw new Exception(sprintf(
'The request method "%s" is not supported',
$request->getMethod()
));
View
@@ -11,7 +11,7 @@
namespace Symfony\Component\Form;
-use Symfony\Component\Form\Exception\FormException;
+use Symfony\Component\Form\Exception\Exception;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\AlreadyBoundException;
use Symfony\Component\Form\Exception\TransformationFailedException;
@@ -152,7 +152,7 @@ public function __construct(FormConfigInterface $config)
// `setData` and `add` will not lead to the correct population of
// the child forms.
if ($config->getCompound() && !$config->getDataMapper()) {
- throw new FormException('Compound forms need a data mapper');
+ throw new Exception('Compound forms need a data mapper');
}
$this->config = $config;
@@ -256,7 +256,7 @@ public function setParent(FormInterface $parent = null)
}
if (null !== $parent && '' === $this->config->getName()) {
- throw new FormException('A form with an empty name cannot have a parent form.');
+ throw new Exception('A form with an empty name cannot have a parent form.');
}
$this->parent = $parent;
@@ -359,7 +359,7 @@ public function setData($modelData)
}
if ($this->lockSetData) {
- throw new FormException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.');
+ throw new Exception('A cycle was detected. Listeners to the PRE_SET_DATA event must not call setData(). You should call setData() on the FormEvent object instead.');
}
$this->lockSetData = true;
@@ -394,7 +394,7 @@ public function setData($modelData)
if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) {
$expectedType = 'scalar, array or an instance of \ArrayAccess';
- throw new FormException(
+ throw new Exception(
'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 ' .
@@ -404,7 +404,7 @@ public function setData($modelData)
}
if (null !== $dataClass && !$viewData instanceof $dataClass) {
- throw new FormException(
+ throw new Exception(
'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 ' .
@@ -867,7 +867,7 @@ public function add($child, $type = null, array $options = array())
}
if (!$this->config->getCompound()) {
- throw new FormException('You cannot add children to a simple form. Maybe you should set the option "compound" to true?');
+ throw new Exception('You cannot add children to a simple form. Maybe you should set the option "compound" to true?');
}
// Obtain the view data
View
@@ -11,7 +11,7 @@
namespace Symfony\Component\Form;
-use Symfony\Component\Form\Exception\FormException;
+use Symfony\Component\Form\Exception\Exception;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -65,7 +65,7 @@ public function __construct($name, $dataClass, EventDispatcherInterface $dispatc
public function add($child, $type = null, array $options = array())
{
if ($this->locked) {
- throw new FormException('The form builder cannot be modified anymore.');
+ throw new Exception('The form builder cannot be modified anymore.');
}
if ($child instanceof self) {
@@ -102,7 +102,7 @@ public function add($child, $type = null, array $options = array())
public function create($name, $type = null, array $options = array())
{
if ($this->locked) {
- throw new FormException('The form builder cannot be modified anymore.');
+ throw new Exception('The form builder cannot be modified anymore.');
}
if (null === $type && null === $this->getDataClass()) {
@@ -129,7 +129,7 @@ public function get($name)
return $this->children[$name];
}
- throw new FormException(sprintf('The child with the name "%s" does not exist.', $name));
+ throw new Exception(sprintf('The child with the name "%s" does not exist.', $name));
}
/**
@@ -138,7 +138,7 @@ public function get($name)
public function remove($name)
{
if ($this->locked) {
- throw new FormException('The form builder cannot be modified anymore.');
+ throw new Exception('The form builder cannot be modified anymore.');
}
unset($this->unresolvedChildren[$name]);
@@ -217,7 +217,7 @@ public function getParent()
public function setParent(FormBuilderInterface $parent = null)
{
if ($this->locked) {
- throw new FormException('The form builder cannot be modified anymore.');
+ throw new Exception('The form builder cannot be modified anymore.');
}
$this->parent = $parent;
Oops, something went wrong.

0 comments on commit 0d87430

Please sign in to comment.