Merge branch '5.0' into 5.1
* 5.0: cs fix add german translation of the html5 color validation Fix PHP 8 deprecations ensure compatibility with PHP 8 stack traces clean up HHVM instructions sync translations from master branch silently ignore uninitialized properties when mapping data to forms
This commit is contained in:
commit
8ecd0c9040
@ -190,12 +190,17 @@ class ClassExistenceResource implements SelfCheckingResourceInterface
|
|||||||
'args' => [$class],
|
'args' => [$class],
|
||||||
];
|
];
|
||||||
|
|
||||||
if (false === $i = array_search($autoloadFrame, $trace, true)) {
|
if (\PHP_VERSION_ID >= 80000 && isset($trace[1])) {
|
||||||
|
$callerFrame = $trace[1];
|
||||||
|
$i = 2;
|
||||||
|
} elseif (false !== $i = array_search($autoloadFrame, $trace, true)) {
|
||||||
|
$callerFrame = $trace[++$i];
|
||||||
|
} else {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($trace[++$i]['function']) && !isset($trace[$i]['class'])) {
|
if (isset($callerFrame['function']) && !isset($callerFrame['class'])) {
|
||||||
switch ($trace[$i]['function']) {
|
switch ($callerFrame['function']) {
|
||||||
case 'get_class_methods':
|
case 'get_class_methods':
|
||||||
case 'get_class_vars':
|
case 'get_class_vars':
|
||||||
case 'get_parent_class':
|
case 'get_parent_class':
|
||||||
@ -214,8 +219,8 @@ class ClassExistenceResource implements SelfCheckingResourceInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$props = [
|
$props = [
|
||||||
'file' => isset($trace[$i]['file']) ? $trace[$i]['file'] : null,
|
'file' => isset($callerFrame['file']) ? $callerFrame['file'] : null,
|
||||||
'line' => isset($trace[$i]['line']) ? $trace[$i]['line'] : null,
|
'line' => isset($callerFrame['line']) ? $callerFrame['line'] : null,
|
||||||
'trace' => \array_slice($trace, 1 + $i),
|
'trace' => \array_slice($trace, 1 + $i),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ namespace Symfony\Component\Form\Extension\Core\DataMapper;
|
|||||||
|
|
||||||
use Symfony\Component\Form\DataMapperInterface;
|
use Symfony\Component\Form\DataMapperInterface;
|
||||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||||
|
use Symfony\Component\PropertyAccess\Exception\AccessException;
|
||||||
|
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ class PropertyPathMapper implements DataMapperInterface
|
|||||||
$config = $form->getConfig();
|
$config = $form->getConfig();
|
||||||
|
|
||||||
if (!$empty && null !== $propertyPath && $config->getMapped()) {
|
if (!$empty && null !== $propertyPath && $config->getMapped()) {
|
||||||
$form->setData($this->propertyAccessor->getValue($data, $propertyPath));
|
$form->setData($this->getPropertyValue($data, $propertyPath));
|
||||||
} else {
|
} else {
|
||||||
$form->setData($config->getData());
|
$form->setData($config->getData());
|
||||||
}
|
}
|
||||||
@ -76,16 +78,32 @@ class PropertyPathMapper implements DataMapperInterface
|
|||||||
$propertyValue = $form->getData();
|
$propertyValue = $form->getData();
|
||||||
// If the field is of type DateTimeInterface and the data is the same skip the update to
|
// If the field is of type DateTimeInterface and the data is the same skip the update to
|
||||||
// keep the original object hash
|
// keep the original object hash
|
||||||
if ($propertyValue instanceof \DateTimeInterface && $propertyValue == $this->propertyAccessor->getValue($data, $propertyPath)) {
|
if ($propertyValue instanceof \DateTimeInterface && $propertyValue == $this->getPropertyValue($data, $propertyPath)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the data is identical to the value in $data, we are
|
// If the data is identical to the value in $data, we are
|
||||||
// dealing with a reference
|
// dealing with a reference
|
||||||
if (!\is_object($data) || !$config->getByReference() || $propertyValue !== $this->propertyAccessor->getValue($data, $propertyPath)) {
|
if (!\is_object($data) || !$config->getByReference() || $propertyValue !== $this->getPropertyValue($data, $propertyPath)) {
|
||||||
$this->propertyAccessor->setValue($data, $propertyPath, $propertyValue);
|
$this->propertyAccessor->setValue($data, $propertyPath, $propertyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getPropertyValue($data, $propertyPath)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return $this->propertyAccessor->getValue($data, $propertyPath);
|
||||||
|
} catch (AccessException $e) {
|
||||||
|
if (!$e instanceof UninitializedPropertyException
|
||||||
|
// For versions without UninitializedPropertyException check the exception message
|
||||||
|
&& (class_exists(UninitializedPropertyException::class) || false === strpos($e->getMessage(), 'You should initialize it'))
|
||||||
|
) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
|
<source>The CSRF token is invalid. Please try to resubmit the form.</source>
|
||||||
<target>Der CSRF-Token ist ungültig. Versuchen Sie bitte das Formular erneut zu senden.</target>
|
<target>Der CSRF-Token ist ungültig. Versuchen Sie bitte das Formular erneut zu senden.</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
|
<trans-unit id="99">
|
||||||
|
<source>This value is not a valid HTML5 color.</source>
|
||||||
|
<target>Dieser Wert ist keine gültige HTML5 Farbe.</target>
|
||||||
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
@ -17,6 +17,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|||||||
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
|
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
|
||||||
use Symfony\Component\Form\Form;
|
use Symfony\Component\Form\Form;
|
||||||
use Symfony\Component\Form\FormConfigBuilder;
|
use Symfony\Component\Form\FormConfigBuilder;
|
||||||
|
use Symfony\Component\Form\Tests\Fixtures\TypehintedPropertiesCar;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccess;
|
use Symfony\Component\PropertyAccess\PropertyAccess;
|
||||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||||
use Symfony\Component\PropertyAccess\PropertyPath;
|
use Symfony\Component\PropertyAccess\PropertyPath;
|
||||||
@ -113,6 +114,23 @@ class PropertyPathMapperTest extends TestCase
|
|||||||
$this->assertNull($form->getData());
|
$this->assertNull($form->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 7.4
|
||||||
|
*/
|
||||||
|
public function testMapDataToFormsIgnoresUninitializedProperties()
|
||||||
|
{
|
||||||
|
$engineForm = new Form(new FormConfigBuilder('engine', null, $this->dispatcher));
|
||||||
|
$colorForm = new Form(new FormConfigBuilder('color', null, $this->dispatcher));
|
||||||
|
|
||||||
|
$car = new TypehintedPropertiesCar();
|
||||||
|
$car->engine = 'BMW';
|
||||||
|
|
||||||
|
$this->mapper->mapDataToForms($car, [$engineForm, $colorForm]);
|
||||||
|
|
||||||
|
$this->assertSame($car->engine, $engineForm->getData());
|
||||||
|
$this->assertNull($colorForm->getData());
|
||||||
|
}
|
||||||
|
|
||||||
public function testMapDataToFormsSetsDefaultDataIfPassedDataIsNull()
|
public function testMapDataToFormsSetsDefaultDataIfPassedDataIsNull()
|
||||||
{
|
{
|
||||||
$default = new \stdClass();
|
$default = new \stdClass();
|
||||||
@ -293,13 +311,28 @@ class PropertyPathMapperTest extends TestCase
|
|||||||
$config->setPropertyPath($propertyPath);
|
$config->setPropertyPath($propertyPath);
|
||||||
$config->setData($engine);
|
$config->setData($engine);
|
||||||
$config->setDisabled(true);
|
$config->setDisabled(true);
|
||||||
$form = new Form($config);
|
$form = new SubmittedForm($config);
|
||||||
|
|
||||||
$this->mapper->mapFormsToData([$form], $car);
|
$this->mapper->mapFormsToData([$form], $car);
|
||||||
|
|
||||||
$this->assertSame($initialEngine, $car->engine);
|
$this->assertSame($initialEngine, $car->engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 7.4
|
||||||
|
*/
|
||||||
|
public function testMapFormsToUninitializedProperties()
|
||||||
|
{
|
||||||
|
$car = new TypehintedPropertiesCar();
|
||||||
|
$config = new FormConfigBuilder('engine', null, $this->dispatcher);
|
||||||
|
$config->setData('BMW');
|
||||||
|
$form = new SubmittedForm($config);
|
||||||
|
|
||||||
|
$this->mapper->mapFormsToData([$form], $car);
|
||||||
|
|
||||||
|
$this->assertSame('BMW', $car->engine);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideDate
|
* @dataProvider provideDate
|
||||||
*/
|
*/
|
||||||
@ -339,7 +372,7 @@ class SubmittedForm extends Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NotSynchronizedForm extends Form
|
class NotSynchronizedForm extends SubmittedForm
|
||||||
{
|
{
|
||||||
public function isSynchronized(): bool
|
public function isSynchronized(): bool
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Form\Tests\Fixtures;
|
||||||
|
|
||||||
|
class TypehintedPropertiesCar
|
||||||
|
{
|
||||||
|
public ?string $engine;
|
||||||
|
public ?string $color;
|
||||||
|
}
|
Reference in New Issue
Block a user