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

This commit is contained in:
Christophe Coevoet 2011-07-06 14:20:59 +02:00
parent 082473659e
commit ef022c0c6c
3 changed files with 5 additions and 68 deletions

View File

@ -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

View File

@ -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.
*

View File

@ -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 {}