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 f074bda

Browse filesBrowse files
[Serializer][PropertyInfo] Add support of false built-in type (from PHP 8.2)
1 parent 7f0edd6 commit f074bda
Copy full SHA for f074bda

File tree

7 files changed

+69
-3
lines changed
Filter options

7 files changed

+69
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,21 @@ public function php81TypesProvider()
272272
];
273273
}
274274

275+
/**
276+
* @dataProvider php82TypesProvider
277+
* @requires PHP 8.2
278+
*/
279+
public function testExtractPhp82Type($property, array $type = null)
280+
{
281+
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php82Dummy', $property, []));
282+
}
283+
284+
public function php82TypesProvider()
285+
{
286+
yield ['nil', null];
287+
yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]];
288+
}
289+
275290
/**
276291
* @dataProvider defaultValueProvider
277292
*/
+19Lines 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 <fabien@symfony.com>
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/Type.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Type
2828
public const BUILTIN_TYPE_OBJECT = 'object';
2929
public const BUILTIN_TYPE_ARRAY = 'array';
3030
public const BUILTIN_TYPE_NULL = 'null';
31+
public const BUILTIN_TYPE_FALSE = 'false';
3132
public const BUILTIN_TYPE_CALLABLE = 'callable';
3233
public const BUILTIN_TYPE_ITERABLE = 'iterable';
3334

@@ -45,6 +46,7 @@ class Type
4546
self::BUILTIN_TYPE_OBJECT,
4647
self::BUILTIN_TYPE_ARRAY,
4748
self::BUILTIN_TYPE_CALLABLE,
49+
self::BUILTIN_TYPE_FALSE,
4850
self::BUILTIN_TYPE_NULL,
4951
self::BUILTIN_TYPE_ITERABLE,
5052
];

‎src/Symfony/Component/PropertyInfo/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/PropertyInfo/composer.json
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"symfony/polyfill-php80": "^1.16"
2929
},
3030
"require-dev": {
31-
"symfony/serializer": "^3.4|^4.0|^5.0",
31+
"symfony/serializer": "^3.4|^4.4.42|^5.0",
3232
"symfony/cache": "^3.4|^4.0|^5.0",
3333
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
3434
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
@@ -37,7 +37,8 @@
3737
"conflict": {
3838
"phpdocumentor/reflection-docblock": "<3.0|>=3.2.0,<3.2.2",
3939
"phpdocumentor/type-resolver": "<0.3.0|1.3.*",
40-
"symfony/dependency-injection": "<3.4"
40+
"symfony/dependency-injection": "<3.4",
41+
"symfony/serializer": "<4.4.42"
4142
},
4243
"suggest": {
4344
"psr/cache-implementation": "To cache results",

‎src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
483483
return (float) $data;
484484
}
485485

486-
if (('is_'.$builtinType)($data)) {
486+
if (Type::BUILTIN_TYPE_FALSE === $builtinType || ('is_'.$builtinType)($data)) {
487487
return $data;
488488
}
489489
} catch (NotNormalizableValueException $e) {
+17Lines 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 <fabien@symfony.com>
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+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
5252
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
5353
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo;
54+
use Symfony\Component\Serializer\Tests\Fixtures\FalseBuiltInDummy;
5455
use Symfony\Component\Serializer\Tests\Fixtures\NormalizableTraversableDummy;
5556
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
5657
use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
@@ -572,6 +573,17 @@ public function testUnionTypeDeserializable()
572573
$this->assertEquals(new DummyUnionType(), $actual, 'Union type denormalization third case failed.');
573574
}
574575

576+
/**
577+
* @requires PHP 8.2
578+
*/
579+
public function testFalseBuiltInTypes()
580+
{
581+
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
582+
$serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['json' => new JsonEncoder()]);
583+
584+
$serializer->deserialize('{"false":false}', FalseBuiltInDummy::class, 'json');
585+
}
586+
575587
private function serializerWithClassDiscriminator()
576588
{
577589
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));

0 commit comments

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