diff --git a/src/Symfony/Component/Form/FormFactory.php b/src/Symfony/Component/Form/FormFactory.php index 5e92baa64f..f7160d5507 100644 --- a/src/Symfony/Component/Form/FormFactory.php +++ b/src/Symfony/Component/Form/FormFactory.php @@ -62,48 +62,29 @@ class FormFactory implements FormFactoryInterface public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = array()) { $name = null; - $typeName = null; if ($type instanceof ResolvedFormTypeInterface) { - if (method_exists($type, 'getBlockPrefix')) { - // As of Symfony 3.0, the block prefix of the type is used as - // default name - $name = $type->getBlockPrefix(); - } else { - // BC - $typeName = $type->getName(); - } + $typeObject = $type; } elseif ($type instanceof FormTypeInterface) { - if (method_exists($type, 'getBlockPrefix')) { - // As of Symfony 3.0, the block prefix of the type is used as - // default name - $name = $type->getBlockPrefix(); - } else { - // BC - $typeName = $type->getName(); - } + $typeObject = $type; } elseif (is_string($type)) { - $resolvedType = $this->registry->getType($type); - if (method_exists($resolvedType, 'getBlockPrefix')) { - // As of Symfony 3.0, the block prefix of the type is used as - // default name - $name = $resolvedType->getBlockPrefix(); - } else { - // BC - $typeName = $type; - } + $typeObject = $this->registry->getType($type); + $name = $type; } else { throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface'); } - // BC when there is no block prefix - if (null === $name) { - if (false === strpos($typeName, '\\')) { - // No FQCN - leave unchanged for BC - $name = $typeName; - } else { + if (method_exists($typeObject, 'getBlockPrefix')) { + // As of Symfony 3.0, the block prefix of the type is used as default name + $name = $typeObject->getBlockPrefix(); + } else { + // BC when there is no block prefix + if (null === $name) { + $name = $typeObject->getName(); + } + if (false !== strpos($name, '\\')) { // FQCN - $name = StringUtil::fqcnToBlockPrefix($typeName); + $name = StringUtil::fqcnToBlockPrefix($name); } } diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php index 0ec0b40590..32b6e73394 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -341,6 +341,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame('FORM', $this->factory->create('TYPE', null, $options)); } + /** + * @group legacy + */ public function testCreateUsesTypeNameIfTypeGivenAsString() { $options = array('a' => '1', 'b' => '2'); @@ -372,6 +375,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame('FORM', $this->factory->create('TYPE', null, $options)); } + /** + * @group legacy + */ public function testCreateStripsNamespaceOffTypeName() { $options = array('a' => '1', 'b' => '2'); @@ -403,6 +409,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame('FORM', $this->factory->create('Vendor\Name\Space\UserForm', null, $options)); } + /** + * @group legacy + */ public function testLegacyCreateStripsNamespaceOffTypeNameAccessByFQCN() { $options = array('a' => '1', 'b' => '2'); @@ -434,6 +443,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame('FORM', $this->factory->create('userform', null, $options)); } + /** + * @group legacy + */ public function testCreateStripsTypeSuffixOffTypeName() { $options = array('a' => '1', 'b' => '2'); @@ -465,6 +477,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame('FORM', $this->factory->create('Vendor\Name\Space\UserType', null, $options)); } + /** + * @group legacy + */ public function testCreateDoesNotStripTypeSuffixIfResultEmpty() { $options = array('a' => '1', 'b' => '2'); @@ -496,6 +511,9 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame('FORM', $this->factory->create('Vendor\Name\Space\Type', null, $options)); } + /** + * @group legacy + */ public function testCreateConvertsTypeToUnderscoreSyntax() { $options = array('a' => '1', 'b' => '2');