Skip to content

Commit b0d0a6f

Browse files
Merge branch '2.3' into 2.7
* 2.3: [DoctrineBridge] Fix required guess of boolean fields [DI] don't use array_map to resolve services Remove dead code in the PropertyPath constructor [Process] Inherit env vars by default in PhpProcess [HttpFoundation] Fixes /0 subnet handling in IpUtils [Form] Simplify DateTimeToStringTransformer Avoid unneeded catch and re-throw of the same exception. [HttpKernel] Remove a duplicate test for the EsiFragmentRenderer Conflicts: src/Symfony/Component/Process/Process.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorCollectionTest.php src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
2 parents 067bb64 + 7757a28 commit b0d0a6f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

Form/DoctrineOrmTypeGuesser.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
namespace Symfony\Bridge\Doctrine\Form;
1313

1414
use Doctrine\Common\Persistence\ManagerRegistry;
15-
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1615
use Doctrine\Common\Persistence\Mapping\MappingException;
16+
use Doctrine\DBAL\Types\Type;
17+
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1718
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
1819
use Symfony\Component\Form\FormTypeGuesserInterface;
1920
use Symfony\Component\Form\Guess\Guess;
@@ -51,28 +52,28 @@ public function guessType($class, $property)
5152
}
5253

5354
switch ($metadata->getTypeOfField($property)) {
54-
case 'array':
55+
case Type::TARRAY:
5556
return new TypeGuess('collection', array(), Guess::MEDIUM_CONFIDENCE);
56-
case 'boolean':
57+
case Type::BOOLEAN:
5758
return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE);
58-
case 'datetime':
59+
case Type::DATETIME:
60+
case Type::DATETIMETZ:
5961
case 'vardatetime':
60-
case 'datetimetz':
6162
return new TypeGuess('datetime', array(), Guess::HIGH_CONFIDENCE);
62-
case 'date':
63+
case Type::DATE:
6364
return new TypeGuess('date', array(), Guess::HIGH_CONFIDENCE);
64-
case 'time':
65+
case Type::TIME:
6566
return new TypeGuess('time', array(), Guess::HIGH_CONFIDENCE);
66-
case 'decimal':
67-
case 'float':
67+
case Type::DECIMAL:
68+
case Type::FLOAT:
6869
return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE);
69-
case 'integer':
70-
case 'bigint':
71-
case 'smallint':
70+
case Type::INTEGER:
71+
case Type::BIGINT:
72+
case Type::SMALLINT:
7273
return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE);
73-
case 'string':
74+
case Type::STRING:
7475
return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);
75-
case 'text':
76+
case Type::TEXT:
7677
return new TypeGuess('textarea', array(), Guess::MEDIUM_CONFIDENCE);
7778
default:
7879
return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);
@@ -95,7 +96,7 @@ public function guessRequired($class, $property)
9596

9697
// Check whether the field exists and is nullable or not
9798
if ($classMetadata->hasField($property)) {
98-
if (!$classMetadata->isNullable($property)) {
99+
if (!$classMetadata->isNullable($property) && Type::BOOLEAN !== $classMetadata->getTypeOfField($property)) {
99100
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
100101
}
101102

@@ -130,7 +131,7 @@ public function guessMaxLength($class, $property)
130131
return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
131132
}
132133

133-
if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
134+
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
134135
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
135136
}
136137
}
@@ -143,7 +144,7 @@ public function guessPattern($class, $property)
143144
{
144145
$ret = $this->getMetadata($class);
145146
if ($ret && $ret[0]->hasField($property) && !$ret[0]->hasAssociation($property)) {
146-
if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
147+
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
147148
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
148149
}
149150
}

0 commit comments

Comments
 (0)