Browse Source

merged branch stof/form_type (PR #1552)

Commits
-------

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

Discussion
----------

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

As discussed on IRC, this removes the magical method to avoid breaking the user-land code by reusing the same name than another type which overrides it. This makes the user aware that a type should have a name as they now have to implement the method themselves.

---------------------------------------------------------------------------

by jalliot at 2011/07/06 05:35:30 -0700

Doc and generator should be modified as well if it's merged.
Fabien Potencier 14 năm trước cách đây
mục cha
commit
befb234e5c

+ 5 - 1
UPDATE.md

@@ -20,10 +20,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 {}