From 66a2676159d5cb1851282c3e2dc6ad47f3bbb3ec Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Sun, 1 Nov 2015 18:02:44 +0100 Subject: [PATCH 1/9] add test --- .../Factory/DefaultChoiceListFactoryTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index 741cde5b43921..3f1912438c7f5 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Form\Tests\ChoiceList\Factory; use Symfony\Component\Form\ChoiceList\ArrayChoiceList; +use Symfony\Component\Form\ChoiceList\ArrayKeyChoiceList; use Symfony\Component\Form\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory; use Symfony\Component\Form\ChoiceList\LazyChoiceList; @@ -574,6 +575,55 @@ public function testCreateViewFlatGroupByOriginalStructure() $this->assertGroupedView($view); } + public function testCreateViewDuplicateArrayKeyChoiceListValues() + { + $list = new ArrayKeyChoiceList( + array( + 'A' => 'a', + 'AA' => 'a', + 'Group 1' => array( + 'E' => 'e', + 'EE' => 'e', + 'A' => 'abc' + ), + 'Group 2' => array( + 'B' => 'b', + 'E' => 'e' + ), + 'AAA' => 'a' + ) + ); + + $view = $this->factory->createView($list); + + $this->assertEquals( + new ChoiceListView( + array( + 0 => new ChoiceView('A', 'A', 'a'), + 1 => new ChoiceView('AA', 'AA', 'a'), + 'Group 1' => new ChoiceGroupView( + 'Group 1', + array( + 2 => new ChoiceView('E', 'E', 'e'), + 3 => new ChoiceView('EE', 'EE', 'e'), + 4 => new ChoiceView('A', 'A', 'abc') + ) + ), + 'Group 2' => new ChoiceGroupView( + 'Group 2', + array( + 5 => new ChoiceView('B', 'B', 'b'), + 6 => new ChoiceView('E', 'E', 'e') + ) + ), + 7 => new ChoiceView('AAA', 'AAA', 'a') + ), + array() + ), + $view + ); + } + public function testCreateViewFlatGroupByEmpty() { $view = $this->factory->createView( From 105ff7388a6d1f9fccbe46e4cf28a03c7adc9f66 Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 00:14:25 +0100 Subject: [PATCH 2/9] addChoiceVIew:key --- .../Factory/DefaultChoiceListFactory.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index ef93ffdd76336..cc40e969a8e23 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -108,7 +108,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, $choice, (string) $value, $label, - $keys, + $keys[(string) $value], $index, $attr, $preferredChoices, @@ -148,11 +148,10 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, return new ChoiceListView($otherViews, $preferredViews); } - private static function addChoiceView($choice, $value, $label, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addChoiceView($choice, $value, $label, $key, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { // $value may be an integer or a string, since it's stored in the array // keys. We want to guarantee it's a string though. - $key = $keys[$value]; $nextIndex = is_int($index) ? $index++ : call_user_func($index, $choice, $key, $value); $view = new ChoiceView( @@ -213,7 +212,7 @@ private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $key $choices[$value], $value, $label, - $keys, + $keys[$value], $index, $attr, $isPreferred, @@ -223,9 +222,9 @@ private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $key } } - private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label, $key, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { - $groupLabel = call_user_func($groupBy, $choice, $keys[$value], $value); + $groupLabel = call_user_func($groupBy, $choice, $key, $value); if (null === $groupLabel) { // If the callable returns null, don't group the choice @@ -233,7 +232,7 @@ private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label $choice, $value, $label, - $keys, + $key, $index, $attr, $isPreferred, @@ -257,7 +256,7 @@ private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label $choice, $value, $label, - $keys, + $key, $index, $attr, $isPreferred, From 355ea1c7300bfd7e9cd424b8ff91cbf968a01dea Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 00:17:34 +0100 Subject: [PATCH 3/9] renaming --- .../Form/ChoiceList/Factory/DefaultChoiceListFactory.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index cc40e969a8e23..68b942a02df98 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -118,7 +118,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, } } else { // Otherwise use the original structure of the choices - self::addChoiceViewsGroupedBy( + self::addStructuredChoiceViews( $list->getStructuredValues(), $label, $choices, @@ -172,9 +172,9 @@ private static function addChoiceView($choice, $value, $label, $key, &$index, $a } } - private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addStructuredChoiceViews($structuredValues, $label, $choices, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { - foreach ($groupBy as $key => $value) { + foreach ($structuredValues as $key => $value) { if (null === $value) { continue; } @@ -184,7 +184,7 @@ private static function addChoiceViewsGroupedBy($groupBy, $label, $choices, $key $preferredViewsForGroup = array(); $otherViewsForGroup = array(); - self::addChoiceViewsGroupedBy( + self::addStructuredChoiceViews( $value, $label, $choices, From 6d15ee7c54d9319ee6c967136985478a36030a8d Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 07:29:54 +0100 Subject: [PATCH 4/9] refactoring --- .../Form/ChoiceList/ArrayChoiceList.php | 25 ++++++++++++++++--- .../Form/ChoiceList/ArrayKeyChoiceList.php | 8 ++++-- .../Factory/DefaultChoiceListFactory.php | 10 ++++---- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 156735b81751e..73b25cfab0294 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -53,6 +53,11 @@ class ArrayChoiceList implements ChoiceListInterface */ protected $valueCallback; + protected $rawChoices; + + protected $rawKeys; + + /** * Creates a list with the given choices and values. * @@ -88,10 +93,12 @@ public function __construct($choices, $value = null) // If the choices are given as recursive array (i.e. with explicit // choice groups), flatten the array. The grouping information is needed // in the view only. - $this->flatten($choices, $value, $choicesByValues, $keysByValues, $structuredValues); + $this->flatten($choices, $value, $choicesByValues, $rawChoices, $keysByValues, $rawKeys, $structuredValues); $this->choices = $choicesByValues; + $this->rawChoices = $rawChoices; $this->originalKeys = $keysByValues; + $this->rawKeys = $rawKeys; $this->structuredValues = $structuredValues; } @@ -127,6 +134,16 @@ public function getOriginalKeys() return $this->originalKeys; } + public function getRawChoices() + { + return $this->rawChoices; + } + + public function getRawKeys() + { + return $this->rawKeys; + } + /** * {@inheritdoc} */ @@ -186,7 +203,7 @@ public function getValuesForChoices(array $choices) * * @internal Must not be used by user-land code */ - protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues) + protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$structuredValues) { if (null === $choicesByValues) { $choicesByValues = array(); @@ -196,14 +213,16 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$keysByVa foreach ($choices as $key => $choice) { if (is_array($choice)) { - $this->flatten($choice, $value, $choicesByValues, $keysByValues, $structuredValues[$key]); + $this->flatten($choice, $value, $choicesByValues, $rawChoices[$key], $keysByValues, $rawKeys[$key], $structuredValues[$key]); continue; } $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; + $rawChoices[$key] = $choiceValue; $keysByValues[$choiceValue] = $key; + $rawKeys[$key] = $key; $structuredValues[$key] = $choiceValue; } } diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php index 7c3c107d0f720..7698aa07622ab 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php @@ -162,24 +162,28 @@ public function getValuesForChoices(array $choices) * * @internal Must not be used by user-land code */ - protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues) + protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$structuredValues) { if (null === $choicesByValues) { $choicesByValues = array(); $keysByValues = array(); $structuredValues = array(); + $rawChoices = array(); + $rawKeys = array(); } foreach ($choices as $choice => $key) { if (is_array($key)) { - $this->flatten($key, $value, $choicesByValues, $keysByValues, $structuredValues[$choice]); + $this->flatten($key, $value, $choicesByValues, $rawChoices[$choice], $keysByValues, $rawKeys[$choice], $structuredValues[$choice]); continue; } $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; + $rawChoices[$choiceValue] = $key; $keysByValues[$choiceValue] = $key; + $rawKeys[$choiceValue] = $choiceValue; $structuredValues[$key] = $choiceValue; } } diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index 68b942a02df98..2b10b399aeddb 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -119,10 +119,10 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, } else { // Otherwise use the original structure of the choices self::addStructuredChoiceViews( - $list->getStructuredValues(), + $list->getRawChoices(), $label, $choices, - $keys, + $list->getRawKeys(), $index, $attr, $preferredChoices, @@ -188,7 +188,7 @@ private static function addStructuredChoiceViews($structuredValues, $label, $cho $value, $label, $choices, - $keys, + $keys[$key], $index, $attr, $isPreferred, @@ -209,10 +209,10 @@ private static function addStructuredChoiceViews($structuredValues, $label, $cho // Add ungrouped items directly self::addChoiceView( - $choices[$value], + $choices[$structuredValues[$key]], $value, $label, - $keys[$value], + $key, $index, $attr, $isPreferred, From 61cba4b76017918337bdf0b9a8755749ea03c1cb Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 10:33:58 +0100 Subject: [PATCH 5/9] fix duplicate values --- .../Form/ChoiceList/ArrayChoiceList.php | 18 +++++-- .../Form/ChoiceList/ArrayKeyChoiceList.php | 9 ++-- .../Factory/DefaultChoiceListFactory.php | 20 +++---- .../Factory/DefaultChoiceListFactoryTest.php | 52 +++++++++++++++++++ 4 files changed, 81 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 73b25cfab0294..737d54731e90d 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -57,6 +57,7 @@ class ArrayChoiceList implements ChoiceListInterface protected $rawKeys; + protected $rawLabels; /** * Creates a list with the given choices and values. @@ -93,12 +94,13 @@ public function __construct($choices, $value = null) // If the choices are given as recursive array (i.e. with explicit // choice groups), flatten the array. The grouping information is needed // in the view only. - $this->flatten($choices, $value, $choicesByValues, $rawChoices, $keysByValues, $rawKeys, $structuredValues); + $this->flatten($choices, $value, $choicesByValues, $rawChoices, $keysByValues, $rawKeys, $rawLabels, $structuredValues); $this->choices = $choicesByValues; $this->rawChoices = $rawChoices; $this->originalKeys = $keysByValues; $this->rawKeys = $rawKeys; + $this->rawLabels = $rawLabels; $this->structuredValues = $structuredValues; } @@ -144,6 +146,11 @@ public function getRawKeys() return $this->rawKeys; } + public function getRawLabels() + { + return $this->rawLabels; + } + /** * {@inheritdoc} */ @@ -203,7 +210,7 @@ public function getValuesForChoices(array $choices) * * @internal Must not be used by user-land code */ - protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$structuredValues) + protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$rawLabels, &$structuredValues) { if (null === $choicesByValues) { $choicesByValues = array(); @@ -213,16 +220,17 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoic foreach ($choices as $key => $choice) { if (is_array($choice)) { - $this->flatten($choice, $value, $choicesByValues, $rawChoices[$key], $keysByValues, $rawKeys[$key], $structuredValues[$key]); + $this->flatten($choice, $value, $choicesByValues, $rawChoices[$key], $keysByValues, $rawKeys[$key], $rawLabels[$key], $structuredValues[$key]); continue; } $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; - $rawChoices[$key] = $choiceValue; + $rawChoices[$key] = $choice; $keysByValues[$choiceValue] = $key; - $rawKeys[$key] = $key; + $rawKeys[$key] = $choiceValue; + $rawLabels[$key] = $key; $structuredValues[$key] = $choiceValue; } } diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php index 7698aa07622ab..13703c34bfe2c 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php @@ -162,7 +162,7 @@ public function getValuesForChoices(array $choices) * * @internal Must not be used by user-land code */ - protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$structuredValues) + protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$rawLabels, &$structuredValues) { if (null === $choicesByValues) { $choicesByValues = array(); @@ -174,16 +174,17 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoic foreach ($choices as $choice => $key) { if (is_array($key)) { - $this->flatten($key, $value, $choicesByValues, $rawChoices[$choice], $keysByValues, $rawKeys[$choice], $structuredValues[$choice]); + $this->flatten($key, $value, $choicesByValues, $rawChoices[$choice], $keysByValues, $rawKeys[$choice], $rawLabels[$choice], $structuredValues[$choice]); continue; } $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; - $rawChoices[$choiceValue] = $key; + $rawChoices[$choice] = $choiceValue; $keysByValues[$choiceValue] = $key; - $rawKeys[$choiceValue] = $choiceValue; + $rawKeys[$choice] = $choiceValue; + $rawLabels[$choice] = $key; $structuredValues[$key] = $choiceValue; } } diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index 2b10b399aeddb..a5efd0dfdca2f 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -123,6 +123,7 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, $label, $choices, $list->getRawKeys(), + $list->getRawLabels(), $index, $attr, $preferredChoices, @@ -148,31 +149,31 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, return new ChoiceListView($otherViews, $preferredViews); } - private static function addChoiceView($choice, $value, $label, $key, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addChoiceView($data, $value, $label, $key, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { // $value may be an integer or a string, since it's stored in the array // keys. We want to guarantee it's a string though. - $nextIndex = is_int($index) ? $index++ : call_user_func($index, $choice, $key, $value); + $nextIndex = is_int($index) ? $index++ : call_user_func($index, $data, $key, $value); $view = new ChoiceView( - $choice, + $data, $value, // If the labels are null, use the original choice key by default - null === $label ? (string) $key : (string) call_user_func($label, $choice, $key, $value), + null === $label ? (string) $key : (string) call_user_func($label, $data, $key, $value), // The attributes may be a callable or a mapping from choice indices // to nested arrays - is_callable($attr) ? call_user_func($attr, $choice, $key, $value) : (isset($attr[$key]) ? $attr[$key] : array()) + is_callable($attr) ? call_user_func($attr, $data, $key, $value) : (isset($attr[$key]) ? $attr[$key] : array()) ); // $isPreferred may be null if no choices are preferred - if ($isPreferred && call_user_func($isPreferred, $choice, $key, $value)) { + if ($isPreferred && call_user_func($isPreferred, $data, $key, $value)) { $preferredViews[$nextIndex] = $view; } else { $otherViews[$nextIndex] = $view; } } - private static function addStructuredChoiceViews($structuredValues, $label, $choices, $keys, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addStructuredChoiceViews($structuredValues, $label, $choices, $keys, $labels, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { foreach ($structuredValues as $key => $value) { if (null === $value) { @@ -189,6 +190,7 @@ private static function addStructuredChoiceViews($structuredValues, $label, $cho $label, $choices, $keys[$key], + $labels[$key], $index, $attr, $isPreferred, @@ -209,10 +211,10 @@ private static function addStructuredChoiceViews($structuredValues, $label, $cho // Add ungrouped items directly self::addChoiceView( - $choices[$structuredValues[$key]], $value, + $keys[$key], $label, - $key, + $labels[$key], $index, $attr, $isPreferred, diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index 3f1912438c7f5..a9f201ece18c4 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -575,6 +575,58 @@ public function testCreateViewFlatGroupByOriginalStructure() $this->assertGroupedView($view); } + public function testCreateViewDuplicateArrayChoiceListValues() + { + $list = new ArrayChoiceList( + array( + 'A' => 'a', + 'AA' => 'a', + 'Group 1' => array( + 'E' => 'e', + 'EE' => 'e', + 'A' => 'abc' + ), + 'Group 2' => array( + 'B' => 'b', + 'E' => 'e' + ), + 'AAA' => 'a' + ), + function ($choice) { + return $choice; + } + ); + + $view = $this->factory->createView($list); + + $this->assertEquals( + new ChoiceListView( + array( + 0 => new ChoiceView('a', 'a', 'A'), + 1 => new ChoiceView('a', 'a', 'AA'), + 'Group 1' => new ChoiceGroupView( + 'Group 1', + array( + 2 => new ChoiceView('e', 'e', 'E'), + 3 => new ChoiceView('e', 'e', 'EE'), + 4 => new ChoiceView('abc', 'abc', 'A') + ) + ), + 'Group 2' => new ChoiceGroupView( + 'Group 2', + array( + 5 => new ChoiceView('b', 'b', 'B'), + 6 => new ChoiceView('e', 'e', 'E') + ) + ), + 7 => new ChoiceView('a', 'a', 'AAA') + ), + array() + ), + $view + ); + } + public function testCreateViewDuplicateArrayKeyChoiceListValues() { $list = new ArrayKeyChoiceList( From b364d9c55acaff43d275957ff50e193c0526c198 Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 10:46:43 +0100 Subject: [PATCH 6/9] renaming refactoring --- .../Form/ChoiceList/ArrayChoiceList.php | 2 +- .../Form/ChoiceList/ArrayKeyChoiceList.php | 2 +- .../Factory/DefaultChoiceListFactory.php | 26 +++++++++---------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 737d54731e90d..aff23ca418614 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -227,8 +227,8 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoic $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; - $rawChoices[$key] = $choice; $keysByValues[$choiceValue] = $key; + $rawChoices[$key] = $choice; $rawKeys[$key] = $choiceValue; $rawLabels[$key] = $key; $structuredValues[$key] = $choiceValue; diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php index 13703c34bfe2c..7acc80ff557a8 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php @@ -181,8 +181,8 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoic $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; - $rawChoices[$choice] = $choiceValue; $keysByValues[$choiceValue] = $key; + $rawChoices[$choice] = $choiceValue; $rawKeys[$choice] = $choiceValue; $rawLabels[$choice] = $key; $structuredValues[$key] = $choiceValue; diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index a5efd0dfdca2f..05978dbd7c645 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -149,45 +149,45 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, return new ChoiceListView($otherViews, $preferredViews); } - private static function addChoiceView($data, $value, $label, $key, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addChoiceView($data, $value, $labelCallback, $label, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { // $value may be an integer or a string, since it's stored in the array // keys. We want to guarantee it's a string though. - $nextIndex = is_int($index) ? $index++ : call_user_func($index, $data, $key, $value); + $nextIndex = is_int($index) ? $index++ : call_user_func($index, $data, $label, $value); $view = new ChoiceView( $data, $value, // If the labels are null, use the original choice key by default - null === $label ? (string) $key : (string) call_user_func($label, $data, $key, $value), + null === $labelCallback ? (string) $label : (string) call_user_func($labelCallback, $data, $label, $value), // The attributes may be a callable or a mapping from choice indices // to nested arrays - is_callable($attr) ? call_user_func($attr, $data, $key, $value) : (isset($attr[$key]) ? $attr[$key] : array()) + is_callable($attr) ? call_user_func($attr, $data, $label, $value) : (isset($attr[$label]) ? $attr[$label] : array()) ); // $isPreferred may be null if no choices are preferred - if ($isPreferred && call_user_func($isPreferred, $data, $key, $value)) { + if ($isPreferred && call_user_func($isPreferred, $data, $label, $value)) { $preferredViews[$nextIndex] = $view; } else { $otherViews[$nextIndex] = $view; } } - private static function addStructuredChoiceViews($structuredValues, $label, $choices, $keys, $labels, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addStructuredChoiceViews($structuredValues, $labelCallback, $choices, $keys, $labels, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { - foreach ($structuredValues as $key => $value) { - if (null === $value) { + foreach ($structuredValues as $key => $data) { + if (null === $data) { continue; } // Add the contents of groups to new ChoiceGroupView instances - if (is_array($value)) { + if (is_array($data)) { $preferredViewsForGroup = array(); $otherViewsForGroup = array(); self::addStructuredChoiceViews( - $value, - $label, + $data, + $labelCallback, $choices, $keys[$key], $labels[$key], @@ -211,9 +211,9 @@ private static function addStructuredChoiceViews($structuredValues, $label, $cho // Add ungrouped items directly self::addChoiceView( - $value, + $data, $keys[$key], - $label, + $labelCallback, $labels[$key], $index, $attr, From 63509d126307e29d16a3da6e3fba28eec1382240 Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 11:32:01 +0100 Subject: [PATCH 7/9] phpdocs and interfaces --- .../Form/ChoiceList/ArrayChoiceList.php | 63 ++++++++++++++----- .../Form/ChoiceList/ArrayKeyChoiceList.php | 15 +++-- .../Form/ChoiceList/ChoiceListInterface.php | 15 +++++ .../Factory/DefaultChoiceListFactory.php | 28 ++++----- .../Form/ChoiceList/LazyChoiceList.php | 36 +++++++++++ .../ChoiceList/LegacyChoiceListAdapter.php | 24 +++++++ 6 files changed, 146 insertions(+), 35 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index aff23ca418614..74a23d6751460 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -53,11 +53,26 @@ class ArrayChoiceList implements ChoiceListInterface */ protected $valueCallback; + /** + * The raw choice of the choices array. + * + * @var array + */ protected $rawChoices; - protected $rawKeys; + /** + * The raw choice values of the choices array. + * + * @var array + */ + protected $rawChoiceValues; - protected $rawLabels; + /** + * The raw keys of the choices array. + * + * @var int[]|string[] + */ + protected $rawKeys; /** * Creates a list with the given choices and values. @@ -69,6 +84,8 @@ class ArrayChoiceList implements ChoiceListInterface * for a choice. If `null` is passed, * incrementing integers are used as * values + * + * @throws UnexpectedTypeException */ public function __construct($choices, $value = null) { @@ -94,14 +111,14 @@ public function __construct($choices, $value = null) // If the choices are given as recursive array (i.e. with explicit // choice groups), flatten the array. The grouping information is needed // in the view only. - $this->flatten($choices, $value, $choicesByValues, $rawChoices, $keysByValues, $rawKeys, $rawLabels, $structuredValues); + $this->flatten($choices, $value, $choicesByValues, $keysByValues, $structuredValues, $rawChoices, $rawChoiceValues, $rawKeys); $this->choices = $choicesByValues; - $this->rawChoices = $rawChoices; $this->originalKeys = $keysByValues; - $this->rawKeys = $rawKeys; - $this->rawLabels = $rawLabels; $this->structuredValues = $structuredValues; + $this->rawChoices = $rawChoices; + $this->rawChoiceValues = $rawChoiceValues; + $this->rawKeys = $rawKeys; } /** @@ -136,19 +153,28 @@ public function getOriginalKeys() return $this->originalKeys; } + /** + * {@inheritdoc} + */ public function getRawChoices() { return $this->rawChoices; } - public function getRawKeys() + /** + * {@inheritdoc} + */ + public function getRawChoiceValues() { - return $this->rawKeys; + return $this->rawChoiceValues; } - public function getRawLabels() + /** + * {@inheritdoc} + */ + public function getRawKeys() { - return $this->rawLabels; + return $this->rawKeys; } /** @@ -208,19 +234,26 @@ public function getValuesForChoices(array $choices) * @param array $keysByValues The original keys indexed by the * corresponding values * + * @param $structuredValues + * @param $rawChoices + * @param $rawChoiceValues + * @param $rawKeys * @internal Must not be used by user-land code */ - protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$rawLabels, &$structuredValues) + protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues, &$rawChoices, &$rawChoiceValues, &$rawKeys) { if (null === $choicesByValues) { $choicesByValues = array(); $keysByValues = array(); $structuredValues = array(); + $rawChoices = array(); + $rawChoiceValues = array(); + $rawKeys = array(); } foreach ($choices as $key => $choice) { if (is_array($choice)) { - $this->flatten($choice, $value, $choicesByValues, $rawChoices[$key], $keysByValues, $rawKeys[$key], $rawLabels[$key], $structuredValues[$key]); + $this->flatten($choice, $value, $choicesByValues, $keysByValues, $structuredValues[$key], $rawChoices[$key], $rawChoiceValues[$key], $rawKeys[$key]); continue; } @@ -228,10 +261,10 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoic $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; $keysByValues[$choiceValue] = $key; - $rawChoices[$key] = $choice; - $rawKeys[$key] = $choiceValue; - $rawLabels[$key] = $key; $structuredValues[$key] = $choiceValue; + $rawChoices[$key] = $choice; + $rawChoiceValues[$key] = $choiceValue; + $rawKeys[$key] = $key; } } } diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php index 7acc80ff557a8..76d1fc9d9b2da 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php @@ -160,21 +160,26 @@ public function getValuesForChoices(array $choices) * @param array $keysByValues The original keys indexed by the * corresponding values * + * @param $structuredValues + * @param $rawChoices + * @param $rawChoiceValues + * @param $rawKeys * @internal Must not be used by user-land code */ - protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoices, &$keysByValues, &$rawKeys, &$rawLabels, &$structuredValues) + protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues, &$rawChoices, &$rawChoiceValues, &$rawKeys) { if (null === $choicesByValues) { $choicesByValues = array(); $keysByValues = array(); $structuredValues = array(); $rawChoices = array(); + $rawChoiceValues = array(); $rawKeys = array(); } foreach ($choices as $choice => $key) { if (is_array($key)) { - $this->flatten($key, $value, $choicesByValues, $rawChoices[$choice], $keysByValues, $rawKeys[$choice], $rawLabels[$choice], $structuredValues[$choice]); + $this->flatten($key, $value, $choicesByValues, $keysByValues, $structuredValues[$choice], $rawChoices[$choice], $rawChoiceValues[$choice], $rawKeys[$choice]); continue; } @@ -182,10 +187,10 @@ protected function flatten(array $choices, $value, &$choicesByValues, &$rawChoic $choiceValue = (string) call_user_func($value, $choice); $choicesByValues[$choiceValue] = $choice; $keysByValues[$choiceValue] = $key; - $rawChoices[$choice] = $choiceValue; - $rawKeys[$choice] = $choiceValue; - $rawLabels[$choice] = $key; $structuredValues[$key] = $choiceValue; + $rawChoices[$choice] = $choiceValue; + $rawChoiceValues[$choice] = $choiceValue; + $rawKeys[$choice] = $key; } } } diff --git a/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php b/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php index b59e77bf795a5..c42e1ce4d0022 100644 --- a/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php +++ b/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php @@ -88,6 +88,21 @@ public function getStructuredValues(); */ public function getOriginalKeys(); + /** + * Returns the raw choices. + */ + public function getRawChoices(); + + /** + * Returns the raw choice values. + */ + public function getRawChoiceValues(); + + /** + * Returns the raw keys. + */ + public function getRawKeys(); + /** * Returns the choices corresponding to the given values. * diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index 05978dbd7c645..3071e0cb55509 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -118,12 +118,11 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, } } else { // Otherwise use the original structure of the choices - self::addStructuredChoiceViews( + self::addChoiceViews( $list->getRawChoices(), + $list->getRawChoiceValues(), $label, - $choices, $list->getRawKeys(), - $list->getRawLabels(), $index, $attr, $preferredChoices, @@ -173,9 +172,9 @@ private static function addChoiceView($data, $value, $labelCallback, $label, &$i } } - private static function addStructuredChoiceViews($structuredValues, $labelCallback, $choices, $keys, $labels, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addChoiceViews($dataValues, $values, $labelCallback, $labels, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { - foreach ($structuredValues as $key => $data) { + foreach ($dataValues as $key => $data) { if (null === $data) { continue; } @@ -185,11 +184,10 @@ private static function addStructuredChoiceViews($structuredValues, $labelCallba $preferredViewsForGroup = array(); $otherViewsForGroup = array(); - self::addStructuredChoiceViews( + self::addChoiceViews( $data, + $values[$key], $labelCallback, - $choices, - $keys[$key], $labels[$key], $index, $attr, @@ -212,7 +210,7 @@ private static function addStructuredChoiceViews($structuredValues, $labelCallba // Add ungrouped items directly self::addChoiceView( $data, - $keys[$key], + $values[$key], $labelCallback, $labels[$key], $index, @@ -224,17 +222,17 @@ private static function addStructuredChoiceViews($structuredValues, $labelCallba } } - private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label, $key, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) + private static function addChoiceViewGroupedBy($groupBy, $data, $value, $labelCallback, $label, &$index, $attr, $isPreferred, &$preferredViews, &$otherViews) { - $groupLabel = call_user_func($groupBy, $choice, $key, $value); + $groupLabel = call_user_func($groupBy, $data, $label, $value); if (null === $groupLabel) { // If the callable returns null, don't group the choice self::addChoiceView( - $choice, + $data, $value, + $labelCallback, $label, - $key, $index, $attr, $isPreferred, @@ -255,10 +253,10 @@ private static function addChoiceViewGroupedBy($groupBy, $choice, $value, $label } self::addChoiceView( - $choice, + $data, $value, + $labelCallback, $label, - $key, $index, $attr, $isPreferred, diff --git a/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php index f691d71330715..11a699e0e4ab7 100644 --- a/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/LazyChoiceList.php @@ -101,6 +101,42 @@ public function getStructuredValues() return $this->loadedList->getStructuredValues(); } + /** + * {@inheritdoc} + */ + public function getRawChoices() + { + if (!$this->loadedList) { + $this->loadedList = $this->loader->loadChoiceList($this->value); + } + + return $this->loadedList->getRawChoices(); + } + + /** + * {@inheritdoc} + */ + public function getRawChoiceValues() + { + if (!$this->loadedList) { + $this->loadedList = $this->loader->loadChoiceList($this->value); + } + + return $this->loadedList->getRawChoiceValues(); + } + + /** + * {@inheritdoc} + */ + public function getRawKeys() + { + if (!$this->loadedList) { + $this->loadedList = $this->loader->loadChoiceList($this->value); + } + + return $this->loadedList->getRawKeys(); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php b/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php index 929ef8c290ded..46afd8d2c2ab7 100644 --- a/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php +++ b/src/Symfony/Component/Form/ChoiceList/LegacyChoiceListAdapter.php @@ -101,6 +101,30 @@ public function getOriginalKeys() return array_flip($this->structuredValues); } + /** + * {@inheritdoc} + */ + public function getRawChoices() + { + throw new \BadMethodCallException('Raw choices not support by LegacyChoiceList'); + } + + /** + * {@inheritdoc} + */ + public function getRawChoiceValues() + { + throw new \BadMethodCallException('Raw choice values not support by LegacyChoiceList'); + } + + /** + * {@inheritdoc} + */ + public function getRawKeys() + { + throw new \BadMethodCallException('Raw keys not support by LegacyChoiceList'); + } + /** * {@inheritdoc} */ From d315ab2d7ade2251d43328a8cdfdb665a3f89f75 Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 11:38:26 +0100 Subject: [PATCH 8/9] cosmetics --- .../Component/Form/ChoiceList/ChoiceListInterface.php | 3 +++ .../Form/ChoiceList/Factory/DefaultChoiceListFactory.php | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php b/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php index c42e1ce4d0022..8315ba922d2a9 100644 --- a/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php +++ b/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php @@ -90,16 +90,19 @@ public function getOriginalKeys(); /** * Returns the raw choices. + * @return array The raw choices */ public function getRawChoices(); /** * Returns the raw choice values. + * @return array The raw choice values */ public function getRawChoiceValues(); /** * Returns the raw keys. + * @return int[]|string[] The raw choice keys */ public function getRawKeys(); diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index 3071e0cb55509..3dd97b973be5b 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -103,12 +103,14 @@ public function createView(ChoiceListInterface $list, $preferredChoices = null, // choice is not added to any group if (is_callable($groupBy)) { foreach ($choices as $value => $choice) { + $stringValue = (string) $value; + self::addChoiceViewGroupedBy( $groupBy, $choice, - (string) $value, + $stringValue, $label, - $keys[(string) $value], + $keys[$stringValue], $index, $attr, $preferredChoices, From c6c6ac0cc9ef2e43042652391bb5d9fec14641fd Mon Sep 17 00:00:00 2001 From: Evgeniy Sokolov Date: Tue, 3 Nov 2015 11:41:34 +0100 Subject: [PATCH 9/9] cs --- .../Form/ChoiceList/ArrayChoiceList.php | 2 +- .../Form/ChoiceList/ArrayKeyChoiceList.php | 2 +- .../Form/ChoiceList/ChoiceListInterface.php | 3 +++ .../Factory/DefaultChoiceListFactoryTest.php | 24 +++++++++---------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 74a23d6751460..54c54baedca68 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -233,11 +233,11 @@ public function getValuesForChoices(array $choices) * corresponding values * @param array $keysByValues The original keys indexed by the * corresponding values - * * @param $structuredValues * @param $rawChoices * @param $rawChoiceValues * @param $rawKeys + * * @internal Must not be used by user-land code */ protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues, &$rawChoices, &$rawChoiceValues, &$rawKeys) diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php index 76d1fc9d9b2da..361353b1b98dd 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayKeyChoiceList.php @@ -159,11 +159,11 @@ public function getValuesForChoices(array $choices) * corresponding values * @param array $keysByValues The original keys indexed by the * corresponding values - * * @param $structuredValues * @param $rawChoices * @param $rawChoiceValues * @param $rawKeys + * * @internal Must not be used by user-land code */ protected function flatten(array $choices, $value, &$choicesByValues, &$keysByValues, &$structuredValues, &$rawChoices, &$rawChoiceValues, &$rawKeys) diff --git a/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php b/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php index 8315ba922d2a9..ac13a22cf82f9 100644 --- a/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php +++ b/src/Symfony/Component/Form/ChoiceList/ChoiceListInterface.php @@ -90,18 +90,21 @@ public function getOriginalKeys(); /** * Returns the raw choices. + * * @return array The raw choices */ public function getRawChoices(); /** * Returns the raw choice values. + * * @return array The raw choice values */ public function getRawChoiceValues(); /** * Returns the raw keys. + * * @return int[]|string[] The raw choice keys */ public function getRawKeys(); diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index a9f201ece18c4..32fa0790b6dd6 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -584,13 +584,13 @@ public function testCreateViewDuplicateArrayChoiceListValues() 'Group 1' => array( 'E' => 'e', 'EE' => 'e', - 'A' => 'abc' + 'A' => 'abc', ), 'Group 2' => array( 'B' => 'b', - 'E' => 'e' + 'E' => 'e', ), - 'AAA' => 'a' + 'AAA' => 'a', ), function ($choice) { return $choice; @@ -609,17 +609,17 @@ function ($choice) { array( 2 => new ChoiceView('e', 'e', 'E'), 3 => new ChoiceView('e', 'e', 'EE'), - 4 => new ChoiceView('abc', 'abc', 'A') + 4 => new ChoiceView('abc', 'abc', 'A'), ) ), 'Group 2' => new ChoiceGroupView( 'Group 2', array( 5 => new ChoiceView('b', 'b', 'B'), - 6 => new ChoiceView('e', 'e', 'E') + 6 => new ChoiceView('e', 'e', 'E'), ) ), - 7 => new ChoiceView('a', 'a', 'AAA') + 7 => new ChoiceView('a', 'a', 'AAA'), ), array() ), @@ -636,13 +636,13 @@ public function testCreateViewDuplicateArrayKeyChoiceListValues() 'Group 1' => array( 'E' => 'e', 'EE' => 'e', - 'A' => 'abc' + 'A' => 'abc', ), 'Group 2' => array( 'B' => 'b', - 'E' => 'e' + 'E' => 'e', ), - 'AAA' => 'a' + 'AAA' => 'a', ) ); @@ -658,17 +658,17 @@ public function testCreateViewDuplicateArrayKeyChoiceListValues() array( 2 => new ChoiceView('E', 'E', 'e'), 3 => new ChoiceView('EE', 'EE', 'e'), - 4 => new ChoiceView('A', 'A', 'abc') + 4 => new ChoiceView('A', 'A', 'abc'), ) ), 'Group 2' => new ChoiceGroupView( 'Group 2', array( 5 => new ChoiceView('B', 'B', 'b'), - 6 => new ChoiceView('E', 'E', 'e') + 6 => new ChoiceView('E', 'E', 'e'), ) ), - 7 => new ChoiceView('AAA', 'AAA', 'a') + 7 => new ChoiceView('AAA', 'AAA', 'a'), ), array() ),