Skip to content

Commit

Permalink
[Form] Changed the default value of $flatten in Form::getErrors() to …
Browse files Browse the repository at this point in the history
…true
  • Loading branch information
webmozart committed Jan 10, 2014
1 parent a9268c4 commit 6b3fbb5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion UPGRADE-2.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ Form
After:

```
public function getErrors($deep = false, $flatten = false)
public function getErrors($deep = false, $flatten = true)
{
```
6 changes: 3 additions & 3 deletions UPGRADE-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ UPGRADE FROM 2.x to 3.0
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).
instead with the argument `$deep` set to true and `$flatten` set to false
and cast the returned iterator to a string (if not done implicitly by PHP).

Before:

Expand All @@ -193,7 +193,7 @@ UPGRADE FROM 2.x to 3.0
After:

```
echo $form->getErrors(true);
echo $form->getErrors(true, false);
```


Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public function all()
/**
* {@inheritdoc}
*/
public function getErrors($deep = false, $flatten = false)
public function getErrors($deep = false, $flatten = true)
{
$errors = array();

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ public function getClickedButton()
/**
* {@inheritdoc}
*/
public function getErrors($deep = false, $flatten = false)
public function getErrors($deep = false, $flatten = true)
{
return new FormErrorIterator($this->errors, $this, $deep, $flatten);
}
Expand All @@ -797,7 +797,7 @@ public function getErrors($deep = false, $flatten = false)
*/
public function getErrorsAsString($level = 0)
{
return self::indent((string) $this->getErrors(true), $level);
return self::indent((string) $this->getErrors(true, false), $level);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormErrorIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FormErrorIterator implements \RecursiveIterator, \SeekableIterator, \Array
* @param Boolean $flatten Whether to flatten the recursive list of
* errors into a flat list
*/
public function __construct(array &$errors, FormInterface $form, $deep = false, $flatten = false)
public function __construct(array &$errors, FormInterface $form, $deep = false, $flatten = true)
{
$this->errors = &$errors;
$this->form = $form;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/FormInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function all();
* @since 2.5 Since version 2.5 this method returns a
* {@link FormErrorIterator} instance instead of an array
*/
public function getErrors($deep = false, $flatten = false);
public function getErrors($deep = false, $flatten = true);

/**
* Updates the form with default data.
Expand Down
38 changes: 19 additions & 19 deletions src/Symfony/Component/Form/Tests/CompoundFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,24 +875,17 @@ public function testGetErrorsDeep()
$this->assertSame(
"ERROR: Error 1\n".
"ERROR: Error 2\n".
"Child:\n".
" ERROR: Nested Error\n",
"ERROR: Nested Error\n",
(string) $errors
);

$errorsAsArray = iterator_to_array($errors);

$this->assertSame($error1, $errorsAsArray[0]);
$this->assertSame($error2, $errorsAsArray[1]);
$this->assertInstanceOf('Symfony\Component\Form\FormErrorIterator', $errorsAsArray[2]);

$nestedErrorsAsArray = iterator_to_array($errorsAsArray[2]);

$this->assertCount(1, $nestedErrorsAsArray);
$this->assertSame($nestedError, $nestedErrorsAsArray[0]);
$this->assertSame(
array($error1, $error2, $nestedError),
iterator_to_array($errors)
);
}

public function testGetErrorsDeepFlat()
public function testGetErrorsDeepRecursive()
{
$this->form->addError($error1 = new FormError('Error 1'));
$this->form->addError($error2 = new FormError('Error 2'));
Expand All @@ -901,19 +894,26 @@ public function testGetErrorsDeepFlat()
$childForm->addError($nestedError = new FormError('Nested Error'));
$this->form->add($childForm);

$errors = $this->form->getErrors(true, true);
$errors = $this->form->getErrors(true, false);

$this->assertSame(
"ERROR: Error 1\n".
"ERROR: Error 2\n".
"ERROR: Nested Error\n",
"Child:\n".
" ERROR: Nested Error\n",
(string) $errors
);

$this->assertSame(
array($error1, $error2, $nestedError),
iterator_to_array($errors)
);
$errorsAsArray = iterator_to_array($errors);

$this->assertSame($error1, $errorsAsArray[0]);
$this->assertSame($error2, $errorsAsArray[1]);
$this->assertInstanceOf('Symfony\Component\Form\FormErrorIterator', $errorsAsArray[2]);

$nestedErrorsAsArray = iterator_to_array($errorsAsArray[2]);

$this->assertCount(1, $nestedErrorsAsArray);
$this->assertSame($nestedError, $nestedErrorsAsArray[0]);
}

// Basic cases are covered in SimpleFormTest
Expand Down

0 comments on commit 6b3fbb5

Please sign in to comment.