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 7a07b3a

Browse filesBrowse files
bug #47621 [Serializer] Allow getting discriminated type by class name (TamasSzigeti)
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] Allow getting discriminated type by class name | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | License | MIT Fixing: `ClassDiscriminatorMapping::getMappedObjectType` allows string input but hasn't worked with class name Commits ------- 84041a1 [Serializer] Allow getting discriminated type by class name
2 parents aea3499 + 84041a1 commit 7a07b3a
Copy full SHA for 7a07b3a

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+2
-1
lines changed

‎src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorMapping.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getClassForType(string $type): ?string
5353
public function getMappedObjectType($object): ?string
5454
{
5555
foreach ($this->typesMapping as $type => $typeClass) {
56-
if (is_a($object, $typeClass)) {
56+
if (is_a($object, $typeClass, true)) {
5757
return $type;
5858
}
5959
}

‎src/Symfony/Component/Serializer/Tests/Mapping/ClassDiscriminatorMappingTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Mapping/ClassDiscriminatorMappingTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function testMappedObjectType()
3939
'third' => AbstractDummyThirdChild::class,
4040
]);
4141

42+
$this->assertEquals('first', $mapping->getMappedObjectType(AbstractDummyFirstChild::class));
4243
$this->assertEquals('first', $mapping->getMappedObjectType(new AbstractDummyFirstChild()));
4344
$this->assertNull($mapping->getMappedObjectType(new AbstractDummySecondChild()));
4445
$this->assertSame('third', $mapping->getMappedObjectType(new AbstractDummyThirdChild()));

0 commit comments

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