Removed the magical guessing of the type name to avoid WTF issues
This commit is contained in:
parent
082473659e
commit
ef022c0c6c
@ -17,6 +17,10 @@ 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
|
||||
----------
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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 {}
|
Reference in New Issue
Block a user