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 f6b4c65

Browse filesBrowse files
committed
[Serializer] Revert #54488 to fix BC Break
1 parent 46a4775 commit f6b4c65
Copy full SHA for f6b4c65

File tree

6 files changed

+5
-238
lines changed
Filter options

6 files changed

+5
-238
lines changed

‎src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
106106

107107
$accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
108108
if ($accessorOrMutator) {
109-
$attributeName = $reflectionClass->hasProperty($method->name) ? $method->name : lcfirst($matches[2]);
109+
$attributeName = lcfirst($matches[2]);
110110

111111
if (isset($attributesMetadata[$attributeName])) {
112112
$attributeMetadata = $attributesMetadata[$attributeName];

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
+4-12Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,17 @@ protected function extractAttributes(object $object, ?string $format = null, arr
9595

9696
if (str_starts_with($name, 'get') || str_starts_with($name, 'has')) {
9797
// getters and hassers
98-
$attributeName = $name;
98+
$attributeName = substr($name, 3);
9999

100100
if (!$reflClass->hasProperty($attributeName)) {
101-
$attributeName = substr($attributeName, 3);
102-
103-
if (!$reflClass->hasProperty($attributeName)) {
104-
$attributeName = lcfirst($attributeName);
105-
}
101+
$attributeName = lcfirst($attributeName);
106102
}
107103
} elseif (str_starts_with($name, 'is')) {
108104
// issers
109-
$attributeName = $name;
105+
$attributeName = substr($name, 2);
110106

111107
if (!$reflClass->hasProperty($attributeName)) {
112-
$attributeName = substr($attributeName, 2);
113-
114-
if (!$reflClass->hasProperty($attributeName)) {
115-
$attributeName = lcfirst($attributeName);
116-
}
108+
$attributeName = lcfirst($attributeName);
117109
}
118110
}
119111

‎src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodDummy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodDummy.php
-48Lines changed: 0 additions & 48 deletions
This file was deleted.

‎src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodWithMethodSerializedNameDummy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodWithMethodSerializedNameDummy.php
-62Lines changed: 0 additions & 62 deletions
This file was deleted.

‎src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodWithPropertySerializedNameDummy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Fixtures/SamePropertyAsMethodWithPropertySerializedNameDummy.php
-65Lines changed: 0 additions & 65 deletions
This file was deleted.

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php
-50Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
use Symfony\Component\Serializer\Tests\Fixtures\Php74Dummy;
4242
use Symfony\Component\Serializer\Tests\Fixtures\Php74DummyPrivate;
4343
use Symfony\Component\Serializer\Tests\Fixtures\Php80Dummy;
44-
use Symfony\Component\Serializer\Tests\Fixtures\SamePropertyAsMethodDummy;
45-
use Symfony\Component\Serializer\Tests\Fixtures\SamePropertyAsMethodWithMethodSerializedNameDummy;
46-
use Symfony\Component\Serializer\Tests\Fixtures\SamePropertyAsMethodWithPropertySerializedNameDummy;
4744
use Symfony\Component\Serializer\Tests\Fixtures\SiblingHolder;
4845
use Symfony\Component\Serializer\Tests\Normalizer\Features\AttributesTestTrait;
4946
use Symfony\Component\Serializer\Tests\Normalizer\Features\CacheableObjectAttributesTestTrait;
@@ -874,53 +871,6 @@ public function testNormalizeStdClass()
874871
$this->assertSame(['baz' => 'baz'], $this->normalizer->normalize($o2));
875872
}
876873

877-
public function testSamePropertyAsMethod()
878-
{
879-
$object = new SamePropertyAsMethodDummy('free_trial', 'has_subscribe', 'get_ready', 'is_active');
880-
$expected = [
881-
'freeTrial' => 'free_trial',
882-
'hasSubscribe' => 'has_subscribe',
883-
'getReady' => 'get_ready',
884-
'isActive' => 'is_active',
885-
];
886-
887-
$this->assertSame($expected, $this->normalizer->normalize($object));
888-
}
889-
890-
public function testSamePropertyAsMethodWithPropertySerializedName()
891-
{
892-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
893-
$this->normalizer = new ObjectNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory));
894-
$this->normalizer->setSerializer($this->serializer);
895-
896-
$object = new SamePropertyAsMethodWithPropertySerializedNameDummy('free_trial', 'has_subscribe', 'get_ready', 'is_active');
897-
$expected = [
898-
'free_trial_property' => 'free_trial',
899-
'has_subscribe_property' => 'has_subscribe',
900-
'get_ready_property' => 'get_ready',
901-
'is_active_property' => 'is_active',
902-
];
903-
904-
$this->assertSame($expected, $this->normalizer->normalize($object));
905-
}
906-
907-
public function testSamePropertyAsMethodWithMethodSerializedName()
908-
{
909-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
910-
$this->normalizer = new ObjectNormalizer($classMetadataFactory, new MetadataAwareNameConverter($classMetadataFactory));
911-
$this->normalizer->setSerializer($this->serializer);
912-
913-
$object = new SamePropertyAsMethodWithMethodSerializedNameDummy('free_trial', 'has_subscribe', 'get_ready', 'is_active');
914-
$expected = [
915-
'free_trial_method' => 'free_trial',
916-
'has_subscribe_method' => 'has_subscribe',
917-
'get_ready_method' => 'get_ready',
918-
'is_active_method' => 'is_active',
919-
];
920-
921-
$this->assertSame($expected, $this->normalizer->normalize($object));
922-
}
923-
924874
public function testNormalizeWithIgnoreAnnotationAndPrivateProperties()
925875
{
926876
$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.