Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9284712

Browse files
Merge branch '5.4' into 6.0
* 5.4: [Serializer] Fix AbstractObjectNormalizer not considering pseudo type false [Serializer] Fix JsonSerializableNormalizer ignores circular reference handler in $context [Serializer][PropertyInfo] Fix support for "false" built-in type on PHP 8.2 [ErrorHandler] Fix list of tentative return types Fix CS in Console Table after #45565 Suppress unhandled error in some specific use-cases. fix italian translation for validators
2 parents feadea6 + 8d028be commit 9284712

File tree

12 files changed

+128
-18
lines changed

12 files changed

+128
-18
lines changed

src/Symfony/Component/Console/Command/DumpCompletionCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function configure()
4141
{
4242
$fullCommand = $_SERVER['PHP_SELF'];
4343
$commandName = basename($fullCommand);
44-
$fullCommand = realpath($fullCommand) ?: $fullCommand;
44+
$fullCommand = @realpath($fullCommand) ?: $fullCommand;
4545

4646
$this
4747
->setHelp(<<<EOH

src/Symfony/Component/Console/Helper/Table.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -738,18 +738,18 @@ private function calculateColumnsWidth(iterable $groups)
738738
continue;
739739
}
740740

741-
foreach ($row as $i => $cell) {
742-
if ($cell instanceof TableCell) {
743-
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
744-
$textLength = Helper::width($textContent);
745-
if ($textLength > 0) {
746-
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
747-
foreach ($contentColumns as $position => $content) {
748-
$row[$i + $position] = $content;
741+
foreach ($row as $i => $cell) {
742+
if ($cell instanceof TableCell) {
743+
$textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
744+
$textLength = Helper::width($textContent);
745+
if ($textLength > 0) {
746+
$contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
747+
foreach ($contentColumns as $position => $content) {
748+
$row[$i + $position] = $content;
749+
}
749750
}
750751
}
751752
}
752-
}
753753

754754
$lengths[] = $this->getCellWidth($row, $column);
755755
}

src/Symfony/Component/ErrorHandler/Internal/TentativeTypes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,8 @@ class TentativeTypes
11021102
'isDot' => 'bool',
11031103
'rewind' => 'void',
11041104
'valid' => 'bool',
1105+
'key' => 'mixed',
1106+
'current' => 'mixed',
11051107
'next' => 'void',
11061108
'seek' => 'void',
11071109
],

src/Symfony/Component/Form/Resources/translations/validators.it.xlf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
</trans-unit>
4545
<trans-unit id="106">
4646
<source>Please choose a valid date interval.</source>
47-
<target>Per favore, scegli a valid date interval.</target>
47+
<target>Per favore, scegli un intervallo di date valido.</target>
4848
</trans-unit>
4949
<trans-unit id="107">
5050
<source>Please enter a valid date and time.</source>
51-
<target>Per favore, inserisci a valid date and time.</target>
51+
<target>Per favore, inserisci una data e ora valida.</target>
5252
</trans-unit>
5353
<trans-unit id="108">
5454
<source>Please enter a valid date.</source>
55-
<target>Per favore, inserisci a valid date.</target>
55+
<target>Per favore, inserisci una data valida.</target>
5656
</trans-unit>
5757
<trans-unit id="109">
5858
<source>Please select a valid file.</source>

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,21 @@ public function php81TypesProvider()
301301
];
302302
}
303303

304+
/**
305+
* @dataProvider php82TypesProvider
306+
* @requires PHP 8.2
307+
*/
308+
public function testExtractPhp82Type($property, array $type = null)
309+
{
310+
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy', $property, []));
311+
}
312+
313+
public function php82TypesProvider()
314+
{
315+
yield ['nil', null];
316+
yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]];
317+
}
318+
304319
/**
305320
* @dataProvider defaultValueProvider
306321
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
class Php82Dummy
15+
{
16+
public null $nil = null;
17+
18+
public false $false = false;
19+
}

src/Symfony/Component/PropertyInfo/Type.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ class Type
2424
public const BUILTIN_TYPE_FLOAT = 'float';
2525
public const BUILTIN_TYPE_STRING = 'string';
2626
public const BUILTIN_TYPE_BOOL = 'bool';
27-
public const BUILTIN_TYPE_TRUE = 'true';
28-
public const BUILTIN_TYPE_FALSE = 'false';
2927
public const BUILTIN_TYPE_RESOURCE = 'resource';
3028
public const BUILTIN_TYPE_OBJECT = 'object';
3129
public const BUILTIN_TYPE_ARRAY = 'array';
3230
public const BUILTIN_TYPE_NULL = 'null';
31+
public const BUILTIN_TYPE_FALSE = 'false';
32+
public const BUILTIN_TYPE_TRUE = 'true';
3333
public const BUILTIN_TYPE_CALLABLE = 'callable';
3434
public const BUILTIN_TYPE_ITERABLE = 'iterable';
3535

@@ -43,12 +43,12 @@ class Type
4343
self::BUILTIN_TYPE_FLOAT,
4444
self::BUILTIN_TYPE_STRING,
4545
self::BUILTIN_TYPE_BOOL,
46-
self::BUILTIN_TYPE_TRUE,
47-
self::BUILTIN_TYPE_FALSE,
4846
self::BUILTIN_TYPE_RESOURCE,
4947
self::BUILTIN_TYPE_OBJECT,
5048
self::BUILTIN_TYPE_ARRAY,
5149
self::BUILTIN_TYPE_CALLABLE,
50+
self::BUILTIN_TYPE_FALSE,
51+
self::BUILTIN_TYPE_TRUE,
5252
self::BUILTIN_TYPE_NULL,
5353
self::BUILTIN_TYPE_ITERABLE,
5454
];

src/Symfony/Component/Serializer/Normalizer/JsonSerializableNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class JsonSerializableNormalizer extends AbstractNormalizer
2727
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
2828
{
2929
if ($this->isCircularReference($object, $context)) {
30-
return $this->handleCircularReference($object);
30+
return $this->handleCircularReference($object, $format, $context);
3131
}
3232

3333
if (!$object instanceof \JsonSerializable) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
class FalseBuiltInDummy
15+
{
16+
public false $false = false;
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Marvin Feldmann <[email protected]>
16+
*/
17+
class JsonSerializableCircularReferenceDummy implements \JsonSerializable
18+
{
19+
public function jsonSerialize(): array
20+
{
21+
return [
22+
'me' => $this,
23+
];
24+
}
25+
}

src/Symfony/Component/Serializer/Tests/Normalizer/JsonSerializableNormalizerTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@
1717
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1818
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
1919
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20+
use Symfony\Component\Serializer\Serializer;
2021
use Symfony\Component\Serializer\SerializerInterface;
22+
use Symfony\Component\Serializer\Tests\Fixtures\JsonSerializableCircularReferenceDummy;
2123
use Symfony\Component\Serializer\Tests\Fixtures\JsonSerializableDummy;
24+
use Symfony\Component\Serializer\Tests\Normalizer\Features\CircularReferenceTestTrait;
2225

2326
/**
2427
* @author Fred Cox <[email protected]>
2528
*/
2629
class JsonSerializableNormalizerTest extends TestCase
2730
{
31+
use CircularReferenceTestTrait;
32+
2833
/**
2934
* @var JsonSerializableNormalizer
3035
*/
@@ -86,6 +91,19 @@ public function testCircularNormalize()
8691
$this->assertEquals('string_object', $this->normalizer->normalize(new JsonSerializableDummy()));
8792
}
8893

94+
protected function getNormalizerForCircularReference(array $defaultContext): JsonSerializableNormalizer
95+
{
96+
$normalizer = new JsonSerializableNormalizer(null, null, $defaultContext);
97+
new Serializer([$normalizer]);
98+
99+
return $normalizer;
100+
}
101+
102+
protected function getSelfReferencingModel()
103+
{
104+
return new JsonSerializableCircularReferenceDummy();
105+
}
106+
89107
public function testInvalidDataThrowException()
90108
{
91109
$this->expectException(InvalidArgumentException::class);

src/Symfony/Component/Serializer/Tests/SerializerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
5757
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
5858
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo;
59+
use Symfony\Component\Serializer\Tests\Fixtures\FalseBuiltInDummy;
5960
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
6061
use Symfony\Component\Serializer\Tests\Fixtures\Php74Full;
6162
use Symfony\Component\Serializer\Tests\Fixtures\Php80WithPromotedTypedConstructor;
@@ -750,6 +751,19 @@ public function testUnionTypeDeserializable()
750751
$this->assertEquals(new DummyUnionType(), $actual, 'Union type denormalization third case failed.');
751752
}
752753

754+
/**
755+
* @requires PHP 8.2
756+
*/
757+
public function testFalseBuiltInTypes()
758+
{
759+
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
760+
$serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['json' => new JsonEncoder()]);
761+
762+
$actual = $serializer->deserialize('{"false":false}', FalseBuiltInDummy::class, 'json');
763+
764+
$this->assertEquals(new FalseBuiltInDummy(), $actual);
765+
}
766+
753767
private function serializerWithClassDiscriminator()
754768
{
755769
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));

0 commit comments

Comments
 (0)