8000 [Form] Introduced base ExceptionInterface · symfony/symfony@fee1bf5 · GitHub
[go: up one dir, main page]

Skip to content

Commit fee1bf5

Browse files
committed
[Form] Introduced base ExceptionInterface
1 parent c4a2a2b commit fee1bf5

39 files changed

+159
-102
lines changed

src/Symfony/Bridge/Doctrine/Form/ChoiceList/EntityChoiceList.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
1313

14-
use Symfony\Component\Form\Exception\FormException;
14+
use Symfony\Component\Form\Exception\Exception;
1515
use Symfony\Component\Form\Exception\StringCastException;
1616
use Symfony\Component\Form\Extension\Core\ChoiceList\ObjectChoiceList;
1717
use Doctrine\Common\Persistence\ObjectManager;
@@ -387,12 +387,12 @@ private function load()
387387
*
388388
* @return array The identifier values
389389
*
390-
* @throws FormException If the entity does not exist in Doctrine's identity map
390+
* @throws Exception If the entity does not exist in Doctrine's identity map
391391
*/
392392
private function getIdentifierValues($entity)
393393
{
394394
if (!$this->em->contains($entity)) {
395-
throw new FormException(
395+
throw new Exception(
396396
'Entities passed to the choice field must be managed. Maybe ' .
397397
'persist them in the entity manager?'
398398
);

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Form\Type;
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
15-
use Symfony\Component\Form\Exception\FormException;
15+
use Symfony\Component\Form\Exception\Exception;
1616
use Doctrine\Common\Persistence\ObjectManager;
1717
use Symfony\Component\Form\FormBuilderInterface;
1818
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList;
@@ -134,7 +134,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
134134
$em = $registry->getManagerForClass($options['class']);
135135

136136
if (null === $em) {
137-
throw new FormException(sprintf(
137+
throw new Exception(sprintf(
138138
'Class "%s" seems not to be a managed Doctrine entity. ' .
139139
'Did you forget to map it?',
140140
$options['class']

src/Symfony/Component/Form/AbstractExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form;
1313

14-
use Symfony\Component\Form\Exception\FormException;
14+
use Symfony\Component\Form\Exception\Exception;
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1616

1717
/**
@@ -53,7 +53,7 @@ public function getType($name)
5353
}
5454

5555
if (!isset($this->types[$name])) {
56-
throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
56+
throw new Exception(sprintf('The type "%s" can not be loaded by this extension', $name));
5757
}
5858

5959
return $this->types[$name];

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ CHANGELOG
99
* FormInterface::add() now accepts a FormInterface instance OR a field's name, type and options
1010
* removed special characters between the choice or text fields of DateType unless
1111
the option "format" is set to a custom value
12+
* deprecated FormException and introduced ExceptionInterface instead
1213

1314
2.1.0
1415
-----

src/Symfony/Component/Form/Exception/AlreadyBoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class AlreadyBoundException extends FormException
14+
class AlreadyBoundException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/CreationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
*
1717
* @author Bernhard Schussek <bschussek@gmail.com>
1818
*/
19-
class CreationException extends FormException
19+
class CreationException extends Exception
2020
{
2121
}

src/Symfony/Component/Form/Exception/ErrorMappingException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class ErrorMappingException extends FormException
14+
class ErrorMappingException extends Exception
1515
{
1616
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Exception;
13+
14+
/**
15+
* Base exception class.
16+
*
17+
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*
19+
* @deprecated This class is a replacement for when class FormException was
20+
* used previously. It should not be used and will be removed.
21+
* Occurrences of this class should be replaced by more specialized
22+
* exception classes, preferably derived from SPL exceptions.
23+
*/
24+
class Exception extends \Exception implements ExceptionInterface
25+
{
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Exception;
13+
14+
/**
15+
* Base ExceptionInterface for the Form component.
16+
*
17+
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*/
19+
interface ExceptionInterface extends FormException
20+
{
21+
}

src/Symfony/Component/Form/Exception/FormException.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line number 10000 Diff line change
@@ -11,6 +11,14 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class FormException extends \Exception
14+
/**
15+
* Alias of {@link ExceptionInterface}.
16+
*
17+
* @author Bernhard Schussek <bschussek@gmail.com>
18+
*
19+
* @deprecated This interface was deprecated and will be removed in Symfony 2.3.
20+
* You should code against {@link ExceptionInterface} instead.
21+
*/
22+
interface FormException
1523
{
1624
}

src/Symfony/Component/Form/Exception/InvalidConfigurationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class InvalidConfigurationException extends FormException
14+
class InvalidConfigurationException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/InvalidPropertyException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class InvalidPropertyException extends FormException
14+
class InvalidPropertyException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/InvalidPropertyPathException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class InvalidPropertyPathException extends FormException
14+
class InvalidPropertyPathException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/NotInitializedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class NotInitializedException extends FormException
14+
class NotInitializedException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/NotValidException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class NotValidException extends FormException
14+
class NotValidException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/PropertyAccessDeniedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class PropertyAccessDeniedException extends FormException
14+
class PropertyAccessDeniedException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/StringCastException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class StringCastException extends FormException
14+
class StringCastException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/TransformationFailedException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
/**
1515
* Indicates a value transformation error.
1616
*
17-
* @author Bernhard Schussek <bschussek@gmail.com>
17+
* @author Bernhard Schussek <bschussek@gmail.com>
1818
*/
19-
class TransformationFailedException extends \RuntimeException
19+
class TransformationFailedException extends \RuntimeException implements ExceptionInterface
2020
{
2121
}

src/Symfony/Component/Form/Exception/TypeDefinitionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
*
1717
* @author Bernhard Schussek <bschussek@gmail.com>
1818
*/
19-
class TypeDefinitionException extends FormException
19+
class TypeDefinitionException extends Exception
2020
{
2121
}

src/Symfony/Component/Form/Exception/TypeLoaderException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class TypeLoaderException extends FormException
14+
class TypeLoaderException extends Exception
1515
{
1616
}

src/Symfony/Component/Form/Exception/UnexpectedTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Exception;
1313

14-
class UnexpectedTypeException extends FormException
14+
class UnexpectedTypeException extends Exception
1515
{
1616
public function __construct($value, $expectedType)
1717
{

src/Symfony/Component/Form/Extension/Core/ChoiceList/LazyChoiceList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form\Extension\Core\ChoiceList;
1313

14-
use Symfony\Component\Form\Exception\FormException;
14+
use Symfony\Component\Form\Exception\Exception;
1515

1616
/**
1717
* A choice list that is loaded lazily
@@ -141,7 +141,7 @@ private function load()
141141
$choiceList = $this->loadChoiceList();
142142

143143
if (!$choiceList instanceof ChoiceListInterface) {
144-
throw new FormException('loadChoiceList() should return a ChoiceListInterface instance. Got ' . gettype($choiceList));
144+
throw new Exception('loadChoiceList() should return a ChoiceListInterface instance. Got ' . gettype($choiceList));
145145
}
146146

147147
$this->choiceList = $choiceList;

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Form\FormBuilderInterface;
1616
use Symfony\Component\Form\FormInterface;
1717
use Symfony\Component\Form\FormView;
18-
use Symfony\Component\Form\Exception\FormException;
18+
use Symfony\Component\Form\Exception\Exception;
1919
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
2020
use Symfony\Component\Form\Extension\Core\EventListener\FixRadioInputListener;
2121
use Symfony\Component\Form\Extension\Core\EventListener\FixCheckboxInputListener;
@@ -41,7 +41,7 @@ class ChoiceType extends AbstractType
4141
public function buildForm(FormBuilderInterface $builder, array $options)
4242
{
4343
if (!$options['choice_list'] && !is_array($options['choices']) && !$options['choices'] instanceof \Traversable) {
44-
throw new FormException('Either the option "choices" or "choice_list" must be set.');
44+
throw new Exception('Either the option "choices" or "choice_list" must be set.');
4545
}
4646

4747
if ($options['expanded']) {

src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\Component\Form\FormView;
1818
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
1919
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
20-
use Symfony\Component\Form\Exception\FormException;
20+
use Symfony\Component\Form\Exception\Exception;
2121
use Symfony\Component\OptionsResolver\Options;
2222
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
2323

@@ -61,7 +61,7 @@ public function buildView(FormView $view, FormInterface $form, array $options)
6161

6262
if ($view->parent) {
6363
if ('' === $name) {
64-
throw new FormException('Form node with empty name can be used only as root form node.');
64+
throw new Exception('Form node with empty name can be used only as root form node.');
6565
}
6666

6767
if ('' !== ($parentFullName = $view->parent->vars['full_name'])) {

src/Symfony/Component/Form/Extension/HttpFoundation/EventListener/BindRequestListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\Form\FormEvents;
1515
use Symfony\Component\Form\FormEvent;
16-
use Symfony\Component\Form\Exception\FormException;
16+
use Symfony\Component\Form\Exception\Exception;
1717
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1818
use Symfony\Component\HttpFoundation\Request;
1919

@@ -74,7 +74,7 @@ public function preBind(FormEvent $event)
7474
break;
7575

7676
default:
77-
throw new FormException(sprintf(
77+
throw new Exception(sprintf(
7878
'The request method "%s" is not supported',
7979
$request->getMethod()
8080
));

src/Symfony/Component/Form/Form.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Component\Form;
1313

14-
use Symfony\Component\Form\Exception\FormException;
14+
use Symfony\Component\Form\Exception\Exception;
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1616
use Symfony\Component\Form\Exception\AlreadyBoundException;
1717
use Symfony\Component\Form\Exception\TransformationFailedException;
@@ -152,7 +152,7 @@ public function __construct(FormConfigInterface $config)
152152
// `setData` and `add` will not lead to the correct population of
153153
// the child forms.
154154
if ($config->getCompound() && !$config->getDataMapper()) {
155-
throw new FormException('Compound forms need a data mapper');
155+
throw new Exception('Compound forms need a data mapper');
156156
}
157157

158158
$this->config = $config;
@@ -256,7 +256,7 @@ public function setParent(FormInterface $parent = null)
256256
}
257257

258258
if (null !== $parent && '' === $this->config->getName()) {
259-
throw new FormException('A form with an empty name cannot have a parent form.');
259+
throw new Exception('A form with an empty name cannot have a parent form.');
260260
}
261261

262262
$this->parent = $parent;
@@ -359,7 +359,7 @@ public function setData($modelData)
359359
}
360360

361361
if ($this->lockSetData) {
362-
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.');
362+
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.');
363363
}
364364

365365
$this->lockSetData = true;
@@ -394,7 +394,7 @@ public function setData($modelData)
394394
if (null === $dataClass && is_object($viewData) && !$viewData instanceof \ArrayAccess) {
395395
$expectedType = 'scalar, array or an instance of \ArrayAccess';
396396

397-
throw new FormException(
397+
throw new Exception(
398398
'The form\'s view data is expected to be of type ' . $expectedType . ', ' .
399399
'but is ' . $actualType . '. You ' .
400400
'can avoid this error by setting the "data_class" option to ' .
@@ -404,7 +404,7 @@ public function setData($modelData)
404404
}
405405

406406
if (null !== $dataClass && !$viewData instanceof $dataClass) {
407-
throw new FormException(
407+
throw new Exception(
408408
'The form\'s view data is expected to be an instance of class ' .
409409
$dataClass . ', but is '. $actualType . '. You can avoid this error ' .
410410
'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())
867867
}
868868

869869
if (!$this->config->getCompound()) {
870-
throw new FormException('You cannot add children to a simple form. Maybe you should set the option "compound" to true?');
870+
throw new Exception('You cannot add children to a simple form. Maybe you should set the option "compound" to true?');
871871
}
872872

873873
// Obtain the view data

0 commit comments

Comments
 (0)
0