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 e05d8c6

Browse filesBrowse files
committed
Merge branch '5.4' into 6.4
* 5.4: separate the property info and write info extractors
2 parents aa0b6a1 + 963b29d commit e05d8c6
Copy full SHA for e05d8c6

File tree

Expand file treeCollapse file tree

2 files changed

+27
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+27
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ObjectNormalizer extends AbstractObjectNormalizer
3838

3939
protected $propertyAccessor;
4040
protected $propertyInfoExtractor;
41+
private $writeInfoExtractor;
4142

4243
private readonly \Closure $objectClassResolver;
4344

@@ -53,6 +54,7 @@ public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory
5354

5455
$this->objectClassResolver = ($objectClassResolver ?? static fn ($class) => \is_object($class) ? $class::class : $class)(...);
5556
$this->propertyInfoExtractor = $propertyInfoExtractor ?: new ReflectionExtractor();
57+
$this->writeInfoExtractor = new ReflectionExtractor();
5658
}
5759

5860
public function getSupportedTypes(?string $format): array
@@ -189,8 +191,15 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
189191
return $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
190192
}
191193

192-
return $this->propertyInfoExtractor->isWritable($class, $attribute)
193-
|| ($writeInfo = $this->propertyInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType();
194+
if ($this->propertyInfoExtractor->isWritable($class, $attribute)) {
195+
return true;
196+
}
197+
198+
if (($writeInfo = $this->writeInfoExtractor->getWriteInfo($class, $attribute)) && PropertyWriteInfo::TYPE_NONE !== $writeInfo->getType()) {
199+
return true;
200+
}
201+
202+
return false;
194203
}
195204

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

‎src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,22 @@ public function testConstructorWithObjectDenormalize()
266266
$this->assertEquals('bar', $obj->bar);
267267
}
268268

269+
public function testConstructorWithObjectDenormalizeUsingPropertyInfoExtractor()
270+
{
271+
$serializer = $this->createMock(ObjectSerializerNormalizer::class);
272+
$normalizer = new ObjectNormalizer(null, null, null, null, null, null, [], new PropertyInfoExtractor());
273+
$normalizer->setSerializer($serializer);
274+
275+
$data = new \stdClass();
276+
$data->foo = 'foo';
277+
$data->bar = 'bar';
278+
$data->baz = true;
279+
$data->fooBar = 'foobar';
280+
$obj = $normalizer->denormalize($data, ObjectConstructorDummy::class, 'any');
281+
$this->assertEquals('foo', $obj->getFoo());
282+
$this->assertEquals('bar', $obj->bar);
283+
}
284+
269285
public function testConstructorWithObjectTypeHintDenormalize()
270286
{
271287
$data = [

0 commit comments

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