|
17 | 17 | use Doctrine\Persistence\ManagerRegistry; |
18 | 18 | use Doctrine\Persistence\Mapping\MappingException; |
19 | 19 | use Doctrine\Persistence\Proxy; |
| 20 | +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
| 21 | +use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
| 22 | +use Symfony\Component\Form\Extension\Core\Type\DateIntervalType; |
| 23 | +use Symfony\Component\Form\Extension\Core\Type\DateTimeType; |
| 24 | +use Symfony\Component\Form\Extension\Core\Type\DateType; |
| 25 | +use Symfony\Component\Form\Extension\Core\Type\IntegerType; |
| 26 | +use Symfony\Component\Form\Extension\Core\Type\NumberType; |
| 27 | +use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
| 28 | +use Symfony\Component\Form\Extension\Core\Type\TextType; |
| 29 | +use Symfony\Component\Form\Extension\Core\Type\TimeType; |
20 | 30 | use Symfony\Component\Form\FormTypeGuesserInterface; |
21 | 31 | use Symfony\Component\Form\Guess\Guess; |
22 | 32 | use Symfony\Component\Form\Guess\TypeGuess; |
@@ -51,44 +61,29 @@ public function guessType(string $class, string $property): ?TypeGuess |
51 | 61 | return new TypeGuess('Symfony\Bridge\Doctrine\Form\Type\EntityType', ['em' => $name, 'class' => $mapping['targetEntity'], 'multiple' => $multiple], Guess::HIGH_CONFIDENCE); |
52 | 62 | } |
53 | 63 |
|
54 | | - switch ($metadata->getTypeOfField($property)) { |
55 | | - case Types::ARRAY: |
56 | | - case Types::SIMPLE_ARRAY: |
57 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CollectionType', [], Guess::MEDIUM_CONFIDENCE); |
58 | | - case Types::BOOLEAN: |
59 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CheckboxType', [], Guess::HIGH_CONFIDENCE); |
60 | | - case Types::DATETIME_MUTABLE: |
61 | | - case Types::DATETIMETZ_MUTABLE: |
62 | | - case 'vardatetime': |
63 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE); |
64 | | - case Types::DATETIME_IMMUTABLE: |
65 | | - case Types::DATETIMETZ_IMMUTABLE: |
66 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE); |
67 | | - case Types::DATEINTERVAL: |
68 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateIntervalType', [], Guess::HIGH_CONFIDENCE); |
69 | | - case Types::DATE_MUTABLE: |
70 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', [], Guess::HIGH_CONFIDENCE); |
71 | | - case Types::DATE_IMMUTABLE: |
72 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE); |
73 | | - case Types::TIME_MUTABLE: |
74 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TimeType', [], Guess::HIGH_CONFIDENCE); |
75 | | - case Types::TIME_IMMUTABLE: |
76 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TimeType', ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE); |
77 | | - case Types::DECIMAL: |
78 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\NumberType', ['input' => 'string'], Guess::MEDIUM_CONFIDENCE); |
79 | | - case Types::FLOAT: |
80 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\NumberType', [], Guess::MEDIUM_CONFIDENCE); |
81 | | - case Types::INTEGER: |
82 | | - case Types::BIGINT: |
83 | | - case Types::SMALLINT: |
84 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\IntegerType', [], Guess::MEDIUM_CONFIDENCE); |
85 | | - case Types::STRING: |
86 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::MEDIUM_CONFIDENCE); |
87 | | - case Types::TEXT: |
88 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextareaType', [], Guess::MEDIUM_CONFIDENCE); |
89 | | - default: |
90 | | - return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\TextType', [], Guess::LOW_CONFIDENCE); |
91 | | - } |
| 64 | + return match ($metadata->getTypeOfField($property)) { |
| 65 | + Types::ARRAY, |
| 66 | + Types::SIMPLE_ARRAY => new TypeGuess(CollectionType::class, [], Guess::MEDIUM_CONFIDENCE), |
| 67 | + Types::BOOLEAN => new TypeGuess(CheckboxType::class, [], Guess::HIGH_CONFIDENCE), |
| 68 | + Types::DATETIME_MUTABLE, |
| 69 | + Types::DATETIMETZ_MUTABLE, |
| 70 | + 'vardatetime' => new TypeGuess(DateTimeType::class, [], Guess::HIGH_CONFIDENCE), |
| 71 | + Types::DATETIME_IMMUTABLE, |
| 72 | + Types::DATETIMETZ_IMMUTABLE => new TypeGuess(DateTimeType::class, ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE), |
| 73 | + Types::DATEINTERVAL => new TypeGuess(DateIntervalType::class, [], Guess::HIGH_CONFIDENCE), |
| 74 | + Types::DATE_MUTABLE => new TypeGuess(DateType::class, [], Guess::HIGH_CONFIDENCE), |
| 75 | + Types::DATE_IMMUTABLE => new TypeGuess(DateType::class, ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE), |
| 76 | + Types::TIME_MUTABLE => new TypeGuess(TimeType::class, [], Guess::HIGH_CONFIDENCE), |
| 77 | + Types::TIME_IMMUTABLE => new TypeGuess(TimeType::class, ['input' => 'datetime_immutable'], Guess::HIGH_CONFIDENCE), |
| 78 | + Types::DECIMAL => new TypeGuess(NumberType::class, ['input' => 'string'], Guess::MEDIUM_CONFIDENCE), |
| 79 | + Types::FLOAT => new TypeGuess(NumberType::class, [], Guess::MEDIUM_CONFIDENCE), |
| 80 | + Types::INTEGER, |
| 81 | + Types::BIGINT, |
| 82 | + Types::SMALLINT => new TypeGuess(IntegerType::class, [], Guess::MEDIUM_CONFIDENCE), |
| 83 | + Types::STRING => new TypeGuess(TextType::class, [], Guess::MEDIUM_CONFIDENCE), |
| 84 | + Types::TEXT => new TypeGuess(TextareaType::class, [], Guess::MEDIUM_CONFIDENCE), |
| 85 | + default => new TypeGuess(TextType::class, [], Guess::LOW_CONFIDENCE), |
| 86 | + }; |
92 | 87 | } |
93 | 88 |
|
94 | 89 | /** |
|
0 commit comments