Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ad8230

Browse filesBrowse files
committed
Merge branch '4.4' into 5.4
* 4.4: ignore missing keys when mapping DateTime objects to uninitialized arrays fix writes to static $kernel property [Validator] Hint that `egulias/email-validator` needs to be installed for strict mode as default config
2 parents 33787f4 + a08fd86 commit 0ad8230
Copy full SHA for 0ad8230

File tree

Expand file treeCollapse file tree

5 files changed

+63
-1
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+63
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected static function bootKernel(array $options = [])
8080

8181
$kernel = static::createKernel($options);
8282
$kernel->boot();
83-
self::$kernel = $kernel;
83+
static::$kernel = $kernel;
8484
static::$booted = true;
8585

8686
$container = static::$kernel->getContainer();

‎src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\DataMapperInterface;
1515
use Symfony\Component\Form\Exception\UnexpectedTypeException;
1616
use Symfony\Component\PropertyAccess\Exception\AccessException;
17+
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
1718
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
1819
use Symfony\Component\PropertyAccess\PropertyAccess;
1920
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
@@ -100,6 +101,10 @@ private function getPropertyValue($data, $propertyPath)
100101
try {
101102
return $this->propertyAccessor->getValue($data, $propertyPath);
102103
} catch (AccessException $e) {
104+
if (\is_array($data) && $e instanceof NoSuchIndexException) {
105+
return null;
106+
}
107+
103108
if (!$e instanceof UninitializedPropertyException
104109
// For versions without UninitializedPropertyException check the exception message
105110
&& (class_exists(UninitializedPropertyException::class) || !str_contains($e->getMessage(), 'You should initialize it'))

‎src/Symfony/Component/Form/Tests/CompoundFormTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/CompoundFormTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\Form\Exception\AlreadySubmittedException;
1717
use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
18+
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
19+
use Symfony\Component\Form\Extension\Core\Type\DateType;
1820
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
1921
use Symfony\Component\Form\Extension\Core\Type\TextType;
2022
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
@@ -36,6 +38,7 @@
3638
use Symfony\Component\Form\Tests\Fixtures\Map;
3739
use Symfony\Component\HttpFoundation\File\UploadedFile;
3840
use Symfony\Component\HttpFoundation\Request;
41+
use Symfony\Component\PropertyAccess\PropertyAccess;
3942

4043
class CompoundFormTest extends TestCase
4144
{
@@ -1076,6 +1079,30 @@ public function testFileUpload()
10761079
$this->assertNull($this->form->get('bar')->getData());
10771080
}
10781081

1082+
public function testMapDateTimeObjectsWithEmptyArrayData()
1083+
{
1084+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
1085+
->enableExceptionOnInvalidIndex()
1086+
->getPropertyAccessor();
1087+
$form = $this->factory->createBuilder()
1088+
->setDataMapper(new PropertyPathMapper($propertyAccessor))
1089+
->add('date', DateType::class, [
1090+
'auto_initialize' => false,
1091+
'format' => 'dd/MM/yyyy',
1092+
'html5' => false,
1093+
'model_timezone' => 'UTC',
1094+
'view_timezone' => 'UTC',
1095+
'widget' => 'single_text',
1096+
])
1097+
->getForm();
1098+
1099+
$form->submit([
1100+
'date' => '04/08/2022',
1101+
]);
1102+
1103+
$this->assertEquals(['date' => new \DateTime('2022-08-04', new \DateTimeZone('UTC'))], $form->getData());
1104+
}
1105+
10791106
private function createForm(string $name = 'name', bool $compound = true): FormInterface
10801107
{
10811108
$builder = $this->getBuilder($name);

‎src/Symfony/Component/Form/Tests/Extension/Core/DataMapper/PropertyPathMapperTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/DataMapper/PropertyPathMapperTest.php
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1717
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
18+
use Symfony\Component\Form\Extension\Core\Type\DateType;
1819
use Symfony\Component\Form\Form;
1920
use Symfony\Component\Form\FormConfigBuilder;
21+
use Symfony\Component\Form\FormFactoryBuilder;
2022
use Symfony\Component\Form\Tests\Fixtures\TypehintedPropertiesCar;
2123
use Symfony\Component\PropertyAccess\PropertyAccess;
2224
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
@@ -365,4 +367,28 @@ public function provideDate()
365367
[new \DateTimeImmutable()],
366368
];
367369
}
370+
371+
public function testMapFormsToDataMapsDateTimeInstanceToArrayIfNotSetBefore()
372+
{
373+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
374+
->enableExceptionOnInvalidIndex()
375+
->getPropertyAccessor();
376+
$form = (new FormFactoryBuilder())->getFormFactory()->createBuilder()
377+
->setDataMapper(new PropertyPathMapper($propertyAccessor))
378+
->add('date', DateType::class, [
379+
'auto_initialize' => false,
380+
'format' => 'dd/MM/yyyy',
381+
'html5' => false,
382+
'model_timezone' => 'UTC',
383+
'view_timezone' => 'UTC',
384+
'widget' => 'single_text',
385+
])
386+
->getForm();
387+
388+
$form->submit([
389+
'date' => '04/08/2022',
390+
]);
391+
392+
$this->assertEquals(['date' => new \DateTime('2022-08-04', new \DateTimeZone('UTC'))], $form->getData());
393+
}
368394
}

‎src/Symfony/Component/Validator/Constraints/EmailValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/EmailValidator.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function validate($value, Constraint $constraint)
7070
}
7171

7272
if (null === $constraint->mode) {
73+
if (Email::VALIDATION_MODE_STRICT === $this->defaultMode && !class_exists(EguliasEmailValidator::class)) {
74+
throw new LogicException(sprintf('The "egulias/email-validator" component is required to make the "%s" constraint default to strict mode.', EguliasEmailValidator::class));
75+
}
76+
7377
$constraint->mode = $this->defaultMode;
7478
}
7579

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.