From a9268c4a99e9be4c76d41f8f79c137c236ad8c13 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Tue, 31 Dec 2013 17:24:28 +0100 Subject: [PATCH] [Form] Changed Form::getErrors() to return an iterator and added two optional parameters $deep and $flatten --- UPGRADE-2.5.md | 39 +++ UPGRADE-3.0.md | 16 + .../Resources/views/Form/form_errors.html.php | 2 +- src/Symfony/Component/Form/Button.php | 6 +- src/Symfony/Component/Form/CHANGELOG.md | 3 + src/Symfony/Component/Form/Form.php | 38 ++- .../Component/Form/FormErrorIterator.php | 310 ++++++++++++++++++ src/Symfony/Component/Form/FormInterface.php | 14 +- .../Component/Form/Tests/CompoundFormTest.php | 96 +++++- .../ViolationMapper/ViolationMapperTest.php | 30 +- .../Component/Form/Tests/SimpleFormTest.php | 2 +- 11 files changed, 516 insertions(+), 40 deletions(-) create mode 100644 src/Symfony/Component/Form/FormErrorIterator.php diff --git a/UPGRADE-2.5.md b/UPGRADE-2.5.md index 053d5fa1f756..57335a8c7bef 100644 --- a/UPGRADE-2.5.md +++ b/UPGRADE-2.5.md @@ -5,3 +5,42 @@ Routing ------- * Added a new optional parameter `$requiredSchemes` to `Symfony\Component\Routing\Generator\UrlGenerator::doGenerate()` + +Form +---- + + * The method `FormInterface::getErrors()` now returns an instance of + `Symfony\Component\Form\FormErrorIterator` instead of an array. This object + is traversable, countable and supports array access. However, you can not + pass it to any of PHP's `array_*` functions anymore. You should use + `iterator_to_array()` in those cases where you did. + + Before: + + ``` + $errors = array_map($callback, $form->getErrors()); + ``` + + After: + + ``` + $errors = array_map($callback, iterator_to_array($form->getErrors())); + ``` + + * The method `FormInterface::getErrors()` now has two additional, optional + parameters. Make sure to add these parameters to the method signatures of + your implementations of that interface. + + Before: + + ``` + public function getErrors() + { + ``` + + After: + + ``` + public function getErrors($deep = false, $flatten = false) + { + ``` diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md index aab13e955e47..f566ce98521b 100644 --- a/UPGRADE-3.0.md +++ b/UPGRADE-3.0.md @@ -180,6 +180,22 @@ UPGRADE FROM 2.x to 3.0 * The options "csrf_provider" and "intention" were renamed to "csrf_token_generator" and "csrf_token_id". + * The method `Form::getErrorsAsString()` was removed. Use `Form::getErrors()` + instead with the argument `$deep` set to true and cast the returned iterator + to a string (if not done implicitly by PHP). + + Before: + + ``` + echo $form->getErrorsAsString(); + ``` + + After: + + ``` + echo $form->getErrors(true); + ``` + ### FrameworkBundle diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_errors.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_errors.html.php index da9bec42ec54..77c60d7dfb3d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_errors.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/form_errors.html.php @@ -1,4 +1,4 @@ - + 0): ?>