Skip to content

Commit 1ded85f

Browse files
feature #46675 [Serializer] Add support of true built-in type (from PHP 8.2) (bobahvas, alexandre-daubois)
This PR was merged into the 6.2 branch. Discussion ---------- [Serializer] Add support of true built-in type (from PHP 8.2) | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - RFC: https://wiki.php.net/rfc/true-type Pull request: php/php-src#8326 Same as this PR to add support of `false` and `null` types: #45981 Commits ------- 2ec0453 [Serializer] Add support of true built-in type (from PHP 8.2)
2 parents 96a7485 + 2ec0453 commit 1ded85f

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ public function php82TypesProvider()
313313
{
314314
yield ['nil', null];
315315
yield ['false', [new Type(Type::BUILTIN_TYPE_FALSE)]];
316+
yield ['true', [new Type(Type::BUILTIN_TYPE_TRUE)]];
316317
}
317318

318319
/**

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php82Dummy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ class Php82Dummy
1616
public null $nil = null;
1717

1818
public false $false = false;
19+
20+
public true $true = true;
1921
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private function validateAndDenormalize(array $types, string $currentClass, stri
565565
return (float) $data;
566566
}
567567

568-
if (Type::BUILTIN_TYPE_FALSE === $builtinType && false === $data) {
568+
if ((Type::BUILTIN_TYPE_FALSE === $builtinType && false === $data) || (Type::BUILTIN_TYPE_TRUE === $builtinType && true === $data)) {
569569
return $data;
570570
}
571571

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 <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 TrueBuiltInDummy
15+
{
16+
public true $true = true;
17+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
use Symfony\Component\Serializer\Tests\Fixtures\Php74Full;
6464
use Symfony\Component\Serializer\Tests\Fixtures\Php80WithPromotedTypedConstructor;
6565
use Symfony\Component\Serializer\Tests\Fixtures\TraversableDummy;
66+
use Symfony\Component\Serializer\Tests\Fixtures\TrueBuiltInDummy;
6667
use Symfony\Component\Serializer\Tests\Normalizer\TestDenormalizer;
6768
use Symfony\Component\Serializer\Tests\Normalizer\TestNormalizer;
6869

@@ -795,6 +796,19 @@ public function testFalseBuiltInTypes()
795796
$this->assertEquals(new FalseBuiltInDummy(), $actual);
796797
}
797798

799+
/**
800+
* @requires PHP 8.2
801+
*/
802+
public function testTrueBuiltInTypes()
803+
{
804+
$extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]);
805+
$serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['json' => new JsonEncoder()]);
806+
807+
$actual = $serializer->deserialize('{"true":true}', TrueBuiltInDummy::class, 'json');
808+
809+
$this->assertEquals(new TrueBuiltInDummy(), $actual);
810+
}
811+
798812
private function serializerWithClassDiscriminator()
799813
{
800814
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy