浏览代码

[Form] changed the way default type names are created to avoid collisions

Fabien Potencier 14 年之前
父节点
当前提交
d044498cde

+ 2 - 4
src/Symfony/Component/Form/AbstractType.php

@@ -128,15 +128,13 @@ abstract class AbstractType implements FormTypeInterface
     /**
      * Returns the name of this type.
      *
-     * The default name type is the class name without the Form nor Type suffix
+     * The default name type is the class name, where \ are replaced by _.
      *
      * @return string The name of this type
      */
     public function getName()
     {
-        preg_match('/\\\\(\w+?)(Form)?(Type)?$/i', get_class($this), $matches);
-
-        return strtolower($matches[1]);
+        return strtolower(str_replace('\\', '_', get_class($this)));
     }
 
     /**

+ 4 - 4
tests/Symfony/Tests/Component/Form/AbstractTypeTest.php

@@ -19,28 +19,28 @@ class AbstractTypeTest extends \PHPUnit_Framework_TestCase
     {
         $type = new MyTest();
 
-        $this->assertEquals('mytest', $type->getName());
+        $this->assertEquals('symfony_tests_component_form_mytest', $type->getName());
     }
 
     public function testGetNameWithTypeSuffix()
     {
         $type = new MyTestType();
 
-        $this->assertEquals('mytest', $type->getName());
+        $this->assertEquals('symfony_tests_component_form_mytesttype', $type->getName());
     }
 
     public function testGetNameWithFormSuffix()
     {
         $type = new MyTestForm();
 
-        $this->assertEquals('mytest', $type->getName());
+        $this->assertEquals('symfony_tests_component_form_mytestform', $type->getName());
     }
 
     public function testGetNameWithFormTypeSuffix()
     {
         $type = new MyTestFormType();
 
-        $this->assertEquals('mytest', $type->getName());
+        $this->assertEquals('symfony_tests_component_form_mytestformtype', $type->getName());
     }
 }