Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 2ac0276

Browse files
authored
Merge pull request #12 from codete/sf27-check
Change Form component version detection
2 parents 9230dca + f29b2db commit 2ac0276

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

FieldTypeMapper.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace Codete\FormGeneratorBundle;
44

5-
use Symfony\Component\HttpKernel\Kernel;
6-
75
class FieldTypeMapper
86
{
9-
protected static $typeNS = array(
7+
private static $typeFQCN = null;
8+
9+
private static $typeNS = array(
1010
'Symfony\\Component\\Form\\Extension\\Core\\Type',
11-
'Symfony\\Bridge\\Doctrine\\Form\\Type'
11+
'Symfony\\Bridge\\Doctrine\\Form\\Type',
1212
);
1313

1414
/**
@@ -17,16 +17,18 @@ class FieldTypeMapper
1717
*/
1818
public static function map($type)
1919
{
20-
$sfVersion = intval(Kernel::VERSION);
20+
if (self::$typeFQCN === null) {
21+
self::$typeFQCN = method_exists('\Symfony\Component\Form\AbstractType', 'getBlockPrefix');
22+
}
2123

22-
if (is_null($type) || $sfVersion < 3) {
24+
if (! self::$typeFQCN || $type === null) {
2325
return $type;
2426
}
2527

2628
$formattedType = ucfirst($type);
2729
foreach (self::$typeNS as $nameSpace) {
28-
if (class_exists($nameSpace.'\\'.$formattedType.'Type')) {
29-
return $nameSpace.'\\'.$formattedType.'Type';
30+
if (class_exists($nameSpace . '\\' . $formattedType . 'Type')) {
31+
return $nameSpace . '\\' . $formattedType . 'Type';
3032
}
3133
}
3234

Tests/FieldTypeMapperTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public function testMap($actual, $expected)
1717

1818
public function dataProvider()
1919
{
20-
$sfVersion = \Symfony\Component\HttpKernel\Kernel::MAJOR_VERSION;
21-
22-
if ($sfVersion < 3) {
20+
if (! method_exists('\Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
2321
return array(
2422
array('choice', 'choice'),
2523
array('text', 'text'),

0 commit comments

Comments
 (0)