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

Skip to content

Commit bd395bb

Browse files
Merge branch '6.4' into 7.4
* 6.4: [HttpFoundation] Fix session cookie_lifetime not applied in mock session storage [Serializer] Fix denormalization of magic `__set` properties Add 'sms' to hostless schemes
2 parents b34a943 + fc13cff commit bd395bb

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

Normalizer/ObjectNormalizer.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,18 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
146146
$context = array_intersect_key($context, ['enable_getter_setter_extraction' => true, 'enable_magic_methods_extraction' => true, 'enable_constructor_extraction' => true, 'enable_adder_remover_extraction' => true]);
147147
$cacheKey = $class.$attribute.hash('xxh128', serialize($context));
148148

149-
return self::$isWritableCache[$cacheKey] ??= str_contains($attribute, '.')
150-
|| $this->propertyInfoExtractor->isWritable($class, $attribute, $context)
151-
|| !\in_array($this->writeInfoExtractor->getWriteInfo($class, $attribute, $context)?->getType(), [null, PropertyWriteInfo::TYPE_NONE, PropertyWriteInfo::TYPE_PROPERTY], true);
149+
if (isset(self::$isWritableCache[$cacheKey])) {
150+
return self::$isWritableCache[$cacheKey];
151+
}
152+
153+
if (str_contains($attribute, '.') || $this->propertyInfoExtractor->isWritable($class, $attribute, $context)) {
154+
return self::$isWritableCache[$cacheKey] = true;
155+
}
156+
157+
$writeType = $this->writeInfoExtractor->getWriteInfo($class, $attribute, $context)?->getType();
158+
159+
return self::$isWritableCache[$cacheKey] = !\in_array($writeType, [null, PropertyWriteInfo::TYPE_NONE], true)
160+
&& (PropertyWriteInfo::TYPE_PROPERTY !== $writeType || !property_exists($class, $attribute));
152161
}
153162

154163
private function hasAttributeAccessorMethod(string $class, string $attribute): bool

Tests/Fixtures/MagicSetDummy.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 MagicSetDummy
15+
{
16+
public array $params = [];
17+
18+
public function __set(string $name, mixed $value): void
19+
{
20+
$this->params[$name] = $value;
21+
}
22+
23+
public function __get(string $name)
24+
{
25+
return $this->params[$name] ?? null;
26+
}
27+
28+
public function __isset(string $name): bool
29+
{
30+
return true;
31+
}
32+
}

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
use Symfony\Component\Serializer\Tests\Fixtures\CircularReferenceDummy;
5555
use Symfony\Component\Serializer\Tests\Fixtures\DummyPrivatePropertyWithoutGetter;
5656
use Symfony\Component\Serializer\Tests\Fixtures\DummyWithUnion;
57+
use Symfony\Component\Serializer\Tests\Fixtures\MagicSetDummy;
5758
use Symfony\Component\Serializer\Tests\Fixtures\OtherSerializedNameDummy;
5859
use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy;
5960
use Symfony\Component\Serializer\Tests\Fixtures\Php74DummyPrivate;
@@ -909,6 +910,19 @@ public function testDenormalizeNonExistingAttribute()
909910
);
910911
}
911912

913+
public function testDenormalizeMagicSet()
914+
{
915+
$obj = $this->normalizer->denormalize(
916+
['param1' => 'test', 'param2' => 42],
917+
MagicSetDummy::class,
918+
'any',
919+
[AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => true]
920+
);
921+
922+
$this->assertSame('test', $obj->params['param1']);
923+
$this->assertSame(42, $obj->params['param2']);
924+
}
925+
912926
public function testNoTraversableSupport()
913927
{
914928
$this->assertFalse($this->normalizer->supportsNormalization(new \ArrayObject()));

0 commit comments

Comments
 (0)