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 719e496

Browse filesBrowse files
committed
Example pr symfony#58255
1 parent b9a741b commit 719e496
Copy full SHA for 719e496

File tree

2 files changed

+37
-2
lines changed
Filter options

2 files changed

+37
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
+26-2Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ protected function isAllowedAttribute($classOrObject, string $attribute, ?string
173173
return false;
174174
}
175175

176-
$class = \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject;
176+
$class = $this->getClass($classOrObject);
177177

178178
if ($context['_read_attributes'] ?? true) {
179179
if (!isset(self::$isReadableCache[$class.$attribute])) {
180-
self::$isReadableCache[$class.$attribute] = (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute)) || $this->propertyInfoExtractor->isReadable($class, $attribute) || $this->hasAttributeAccessorMethod($class, $attribute);
180+
self::$isReadableCache[$class.$attribute] = $this->isReadable($classOrObject, $attribute);
181181
}
182182

183183
return self::$isReadableCache[$class.$attribute];
@@ -213,4 +213,28 @@ private function hasAttributeAccessorMethod(string $class, string $attribute): b
213213
&& !$method->getAttributes(Ignore::class)
214214
&& !$method->getNumberOfRequiredParameters();
215215
}
216+
217+
private function isReadable($classOrObject, string $attribute): bool
218+
{
219+
$class = $this->getClass($classOrObject);
220+
221+
if ($this->propertyInfoExtractor->isReadable($class, $attribute)) {
222+
return true;
223+
}
224+
225+
if ($this->hasAttributeAccessorMethod($class, $attribute)) {
226+
return true;
227+
}
228+
229+
if (\is_object($classOrObject) && $this->propertyAccessor->isReadable($classOrObject, $attribute)) {
230+
return true;
231+
}
232+
233+
return false;
234+
}
235+
236+
private function getClass($classOrObject): string
237+
{
238+
return \is_object($classOrObject) ? \get_class($classOrObject) : $classOrObject;
239+
}
216240
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,17 @@ public function testDenormalizeWithPropertyPath()
953953

954954
$this->assertEquals($expected, $obj);
955955
}
956+
957+
public function testObjectNormalizerWithAttributeLoaderAndObjectHasStaticProperty()
958+
{
959+
$class = new class {
960+
public static string $foo;
961+
};
962+
963+
$normalizer = new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()));
964+
$normalizer->normalize($class);
965+
$this->expectNotToPerformAssertions();
966+
}
956967
}
957968

958969
class ProxyObjectDummy extends ObjectDummy

0 commit comments

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