瀏覽代碼

Removed the magical guessing of the type name to avoid WTF issues

Christophe Coevoet 14 年之前
父節點
當前提交
ef022c0c6c
共有 3 個文件被更改,包括 5 次插入68 次删除
  1. 5 1
      UPDATE.md
  2. 0 14
      src/Symfony/Component/Form/AbstractType.php
  3. 0 53
      tests/Symfony/Tests/Component/Form/AbstractTypeTest.php

+ 5 - 1
UPDATE.md

@@ -17,10 +17,14 @@ RC4 to RC5
         framework:
             proxy: true
 
+ * To avoid hidden naming collisions, the AbstractType does not try to define
+   the name of form types magically. You now need to implement the `getName()`
+   method explicitly when creating a custom type.
+
 RC3 to RC4
 ----------
 
-* Annotation classes must be annotated with @Annotation 
+* Annotation classes must be annotated with @Annotation
   (see the validator constraints for examples)
 
 * Annotations are not using the PHP autoloading but their own mechanism. This

+ 0 - 14
src/Symfony/Component/Form/AbstractType.php

@@ -125,20 +125,6 @@ abstract class AbstractType implements FormTypeInterface
         return 'form';
     }
 
-    /**
-     * Returns the name of this type.
-     *
-     * The default name type is the class name without the Form nor Type suffix
-     *
-     * @return string The name of this type
-     */
-    public function getName()
-    {
-        preg_match('/\\\\(\w+?)(Form)?(Type)?$/i', get_class($this), $matches);
-
-        return strtolower($matches[1]);
-    }
-
     /**
      * Adds extensions for this type.
      *

+ 0 - 53
tests/Symfony/Tests/Component/Form/AbstractTypeTest.php

@@ -1,53 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Tests\Component\Form;
-
-use Symfony\Component\Form\AbstractType;
-
-class AbstractTypeTest extends \PHPUnit_Framework_TestCase
-{
-    public function testGetNameWithNoSuffix()
-    {
-        $type = new MyTest();
-
-        $this->assertEquals('mytest', $type->getName());
-    }
-
-    public function testGetNameWithTypeSuffix()
-    {
-        $type = new MyTestType();
-
-        $this->assertEquals('mytest', $type->getName());
-    }
-
-    public function testGetNameWithFormSuffix()
-    {
-        $type = new MyTestForm();
-
-        $this->assertEquals('mytest', $type->getName());
-    }
-
-    public function testGetNameWithFormTypeSuffix()
-    {
-        $type = new MyTestFormType();
-
-        $this->assertEquals('mytest', $type->getName());
-    }
-}
-
-class MyTest extends AbstractType {}
-
-class MyTestType extends AbstractType {}
-
-class MyTestForm extends AbstractType {}
-
-class MyTestFormType extends AbstractType {}