Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 753a08e

Browse files
committed
[Form] Fix Traversable support for choice lists
1 parent a72a5fa commit 753a08e

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@ class ChoiceList implements ChoiceListInterface
8787
*
8888
* @throws UnexpectedTypeException If the choices are not an array or \Traversable.
8989
*/
90-
public function __construct($choices, array $labels, array $preferredChoices = array())
90+
public function __construct($choices, $labels, $preferredChoices = array())
9191
{
9292
if (!is_array($choices) && !$choices instanceof \Traversable) {
9393
throw new UnexpectedTypeException($choices, 'array or \Traversable');
9494
}
9595

96+
if (!is_array($labels) && !$labels instanceof \Traversable) {
97+
throw new UnexpectedTypeException($labels, 'array or \Traversable');
98+
}
99+
100+
if (!is_array($preferredChoices) && !$preferredChoices instanceof \Traversable) {
101+
throw new UnexpectedTypeException($preferredChoices, 'array or \Traversable');
102+
}
103+
96104
$this->initialize($choices, $labels, $preferredChoices);
97105
}
98106

@@ -105,7 +113,7 @@ public function __construct($choices, array $labels, array $preferredChoices = a
105113
* @param array $labels The labels belonging to the choices.
106114
* @param array $preferredChoices The choices to display with priority.
107115
*/
108-
protected function initialize($choices, array $labels, array $preferredChoices)
116+
protected function initialize($choices, $labels, $preferredChoices)
109117
{
110118
$this->choices = array();
111119
$this->values = array();
@@ -271,7 +279,7 @@ public function getIndicesForValues(array $values)
271279
* @throws InvalidArgumentException If the structures of the choices and labels array do not match.
272280
* @throws InvalidConfigurationException If no valid value or index could be created for a choice.
273281
*/
274-
protected function addChoices(array &$bucketForPreferred, array &$bucketForRemaining, $choices, array $labels, array $preferredChoices)
282+
protected function addChoices(array &$bucketForPreferred, array &$bucketForRemaining, $choices, $labels, $preferredChoices)
275283
{
276284
// Add choices to the nested buckets
277285
foreach ($choices as $group => $choice) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class ObjectChoiceList extends ChoiceList
9090
* are generated instead.
9191
* @param PropertyAccessorInterface $propertyAccessor The reflection graph for reading property paths.
9292
*/
93-
public function __construct($choices, $labelPath = null, array $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
93+
public function __construct($choices, $labelPath = null, $preferredChoices = array(), $groupPath = null, $valuePath = null, PropertyAccessorInterface $propertyAccessor = null)
9494
{
9595
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
9696
$this->labelPath = null !== $labelPath ? new PropertyPath($labelPath) : null;
@@ -112,7 +112,7 @@ public function __construct($choices, $labelPath = null, array $preferredChoices
112112
* @throws InvalidArgumentException When passing a hierarchy of choices and using
113113
* the "groupPath" option at the same time.
114114
*/
115-
protected function initialize($choices, array $labels, array $preferredChoices)
115+
protected function initialize($choices, $labels, $preferredChoices)
116116
{
117117
if (null !== $this->groupPath) {
118118
$groupedChoices = array();

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

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

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

14-
@trigger_error('The '.__NAMESPACE__.'\SimpleChoiceList class is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Form\ChoiceList\ArrayChoiceList instead.', E_USER_DEPRECATED);
15-
1614
/**
1715
* A choice list for choices of type string or integer.
1816
*
@@ -30,24 +28,21 @@
3028
* </code>
3129
*
3230
* @author Bernhard Schussek <[email protected]>
33-
*
34-
* @deprecated since version 2.7, to be removed in 3.0.
35-
* Use {@link \Symfony\Component\Form\ChoiceList\ArrayChoiceList} instead.
3631
*/
3732
class SimpleChoiceList extends ChoiceList
3833
{
3934
/**
4035
* Creates a new simple choice list.
4136
*
42-
* @param array $choices The array of choices with the choices as keys and
43-
* the labels as values. Choices may also be given
44-
* as hierarchy of unlimited depth by creating nested
45-
* arrays. The title of the sub-hierarchy is stored
46-
* in the array key pointing to the nested array.
37+
* @param array|\Traversable $choices The array of choices with the choices as keys and
38+
* the labels as values. Choices may also be given
39+
* as hierarchy of unlimited depth by creating nested
40+
* arrays. The title of the sub-hierarchy is stored
41+
* in the array key pointing to the nested array.
4742
* @param array $preferredChoices A flat array of choices that should be
48-
* presented to the user with priority.
43+
* presented to the user with priority.
4944
*/
50-
public function __construct(array $choices, array $preferredChoices = array())
45+
public function __construct($choices, array $preferredChoices = array())
5146
{
5247
// Flip preferred choices to speed up lookup
5348
parent::__construct($choices, $choices, array_flip($preferredChoices));
@@ -91,7 +86,7 @@ public function getValuesForChoices(array $choices)
9186
* @param array $labels Ignored.
9287
* @param array $preferredChoices The preferred choices.
9388
*/
94-
protected function addChoices(array &$bucketForPreferred, array &$bucketForRemaining, $choices, array $labels, array $preferredChoices)
89+
protected function addChoices(array &$bucketForPreferred, array &$bucketForRemaining, $choices, $labels, $preferredChoices)
9590
{
9691
// Add choices to the nested buckets
9792
foreach ($choices as $choice => $label) {

0 commit comments

Comments
 (0)