<
10000
div class="Box-sc-g0xbh4-0 prc-PageLayout-HorizontalDivider-CYLp5 prc-PageLayout-PaneHorizontalDivider-4exOb" data-variant="none" data-position="start" style="--spacing-divider:var(--spacing-none);--spacing:var(--spacing-none)">
File tree 5 files changed +35
-1
lines changed
src/Symfony/Component/Serializer
5 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,18 @@ public function __construct(string $typeProperty, array $typesMapping = [])
23
23
{
24
24
$ this ->typeProperty = $ typeProperty ;
25
25
$ this ->typesMapping = $ typesMapping ;
26
+
27
+ uasort ($ this ->typesMapping , static function (string $ a , string $ b ): int {
28
+ if (is_a ($ a , $ b , true )) {
29
+ return -1 ;
30
+ }
31
+
32
+ if (is_a ($ b , $ a ,
10000
true )) {
33
+ return 1 ;
34
+ }
35
+
36
+ return 0 ;
37
+ });
26
38
}
27
39
28
40
public function getTypeProperty (): string
Original file line number Diff line number Diff line change 16
16
/**
17
17
* @DiscriminatorMap(typeProperty="type", mapping={
18
18
* "first"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyFirstChild",
19
- * "second"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild"
19
+ * "second"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummySecondChild",
20
+ * "third"="Symfony\Component\Serializer\Tests\Fixtures\AbstractDummyThirdChild",
20
21
* })
21
22
*/
22
23
abstract class AbstractDummy
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
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
+ final class AbstractDummyThirdChild extends AbstractDummyFirstChild
15
+ {
16
+ }
Original file line number Diff line number Diff line change 15
15
use Symfony \Component \Serializer \Mapping \ClassDiscriminatorMapping ;
16
16
use Symfony \Component \Serializer \Tests \Fixtures \AbstractDummyFirstChild ;
17
17
use Symfony \Component \Serializer \Tests \Fixtures \AbstractDummySecondChild ;
18
+ use Symfony \Component \Serializer \Tests \Fixtures \AbstractDummyThirdChild ;
18
19
19
20
/**
20
21
* @author Samuel Roze <samuel.roze@gmail.com>
@@ -35,9 +36,11 @@ public function testMappedObjectType()
35
36
{
36
37
$ mapping = new ClassDiscriminatorMapping ('type ' , [
37
38
'first ' => AbstractDummyFirstChild::class,
39
+ 'third ' => AbstractDummyThirdChild::class,
38
40
]);
39
41
40
42
$ this ->assertEquals ('first ' , $ mapping ->getMappedObjectType (new AbstractDummyFirstChild ()));
41
43
$ this ->assertNull ($ mapping ->getMappedObjectType (new AbstractDummySecondChild ()));
44
+ $ this ->assertSame ('third ' , $ mapping ->getMappedObjectType (new AbstractDummyThirdChild ()));
42
45
}
43
46
}
Original file line number Diff line number Diff line change 20
20
use Symfony \Component \Serializer \Tests \Fixtures \AbstractDummy ;
21
21
use Symfony \Component \Serializer \Tests \Fixtures \AbstractDummyFirstChild ;
22
22
use Symfony \Component \Serializer \Tests \Fixtures \AbstractDummySecondChild ;
23
+ use Symfony \Component \Serializer \Tests \Fixtures \AbstractDummyThirdChild ;
23
24
use Symfony \Component \Serializer \Tests \Mapping \TestClassMetadataFactory ;
24
25
25
26
/**
@@ -65,6 +66,7 @@ public function testLoadDiscriminatorMap()
65
66
$ expected = new ClassMetadata (AbstractDummy::class, new ClassDiscriminatorMapping ('type ' , [
66
67
'first ' => AbstractDummyFirstChild::class,
67
68
'second ' => AbstractDummySecondChild::class,
69
+ 'third ' => AbstractDummyThirdChild::class,
68
70
]));
69
71
70
72
$ expected ->addAttributeMetadata (new AttributeMetadata ('foo ' ));
0 commit comments