Browse Source

[Form] Renamed ChoiceUtil to FormUtil and gave its methods more general names

Bernhard Schussek 14 years ago
parent
commit
b93f5a372a

+ 2 - 2
src/Symfony/Component/Form/DataTransformer/ArrayToChoicesTransformer.php

@@ -11,7 +11,7 @@
 
 namespace Symfony\Component\Form\DataTransformer;
 
-use Symfony\Component\Form\Util\ChoiceUtil;
+use Symfony\Component\Form\Util\FormUtil;
 use Symfony\Component\Form\Exception\UnexpectedTypeException;
 
 class ArrayToChoicesTransformer implements DataTransformerInterface
@@ -26,7 +26,7 @@ class ArrayToChoicesTransformer implements DataTransformerInterface
             throw new UnexpectedTypeException($array, 'array');
         }
 
-        return ChoiceUtil::toValidChoiceArray($array);
+        return FormUtil::toArrayKeys($array);
     }
 
     public function reverseTransform($array)

+ 2 - 2
src/Symfony/Component/Form/DataTransformer/ScalarToChoiceTransformer.php

@@ -11,13 +11,13 @@
 
 namespace Symfony\Component\Form\DataTransformer;
 
-use Symfony\Component\Form\Util\ChoiceUtil;
+use Symfony\Component\Form\Util\FormUtil;
 
 class ScalarToChoiceTransformer implements DataTransformerInterface
 {
     public function transform($value)
     {
-        return ChoiceUtil::toValidChoice($value);
+        return FormUtil::toArrayKey($value);
     }
 
     public function reverseTransform($value)

+ 2 - 2
src/Symfony/Component/Form/FormView.php

@@ -12,7 +12,7 @@
 namespace Symfony\Component\Form;
 
 use Symfony\Component\Form\FormInterface;
-use Symfony\Component\Form\Util\ChoiceUtil;
+use Symfony\Component\Form\Util\FormUtil;
 
 class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
 {
@@ -169,7 +169,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
 
     public function isChoiceSelected($choice)
     {
-        $choice = ChoiceUtil::toValidChoice($choice);
+        $choice = FormUtil::toArrayKey($choice);
 
         // The value should already have been converted by value transformers,
         // otherwise we had to do the conversion on every call of this method

+ 4 - 4
src/Symfony/Component/Form/Util/ChoiceUtil.php

@@ -11,9 +11,9 @@
 
 namespace Symfony\Component\Form\Util;
 
-abstract class ChoiceUtil
+abstract class FormUtil
 {
-    public static function toValidChoice($value)
+    public static function toArrayKey($value)
     {
         if ((string)(int)$value === (string)$value) {
             return (int)$value;
@@ -26,8 +26,8 @@ abstract class ChoiceUtil
         return (string)$value;
     }
 
-    public static function toValidChoiceArray(array $array)
+    public static function toArrayKeys(array $array)
     {
-        return array_map(array(__CLASS__, 'toValidChoice'), $array);
+        return array_map(array(__CLASS__, 'toArrayKey'), $array);
     }
 }

+ 1 - 1
tests/Symfony/Tests/Component/Form/DataTransformer/ScalarToChoiceTransformerTest.php

@@ -25,7 +25,7 @@ class ScalarToChoiceTransformerTest extends \PHPUnit_Framework_TestCase
     public function transformProvider()
     {
         return array(
-            // more extensive test set can be found in ChoiceUtilTest
+            // more extensive test set can be found in FormUtilTest
             array(0, 0),
             array(false, 0),
             array('', ''),

+ 9 - 9
tests/Symfony/Tests/Component/Form/Util/ChoiceUtilTest.php

@@ -11,11 +11,11 @@
 
 namespace Symfony\Tests\Component\Form\Util;
 
-use Symfony\Component\Form\Util\ChoiceUtil;
+use Symfony\Component\Form\Util\FormUtil;
 
-class ChoiceUtilTest extends \PHPUnit_Framework_TestCase
+class FormUtilTest extends \PHPUnit_Framework_TestCase
 {
-    public function toValidChoiceProvider()
+    public function toArrayKeyProvider()
     {
         return array(
             array(0, 0),
@@ -32,22 +32,22 @@ class ChoiceUtilTest extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * @dataProvider toValidChoiceProvider
+     * @dataProvider toArrayKeyProvider
      */
-    public function testToValidChoice($in, $out)
+    public function testToArrayKey($in, $out)
     {
-        $this->assertSame($out, ChoiceUtil::toValidChoice($in));
+        $this->assertSame($out, FormUtil::toArrayKey($in));
     }
 
-    public function testToValidChoiceArray()
+    public function testToArrayKeys()
     {
         $in = $out = array();
 
-        foreach ($this->toValidChoiceProvider() as $call) {
+        foreach ($this->toArrayKeyProvider() as $call) {
             $in[] = $call[0];
             $out[] = $call[1];
         }
 
-        $this->assertSame($out, ChoiceUtil::toValidChoiceArray($in));
+        $this->assertSame($out, FormUtil::toArrayKeys($in));
     }
 }