Commit 1b0bfd1
committed
bug #65647 [Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata (oliinykdm)
This PR was merged into the 6.4 branch.
Discussion
----------
[Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix #58526
| License | MIT
`MaxDepth` is counted per runtime class name. A Doctrine proxy is a subclass of the entity, so it gets its own counter. With `max_depth: 1`, a graph of entity → proxy → entity is serialized two levels deep instead of one.
The depth key now uses the parent class when that parent declares the same `MaxDepth` value. A proxy and its entity then share one counter.
```php
$a = new Dossier();
$b = new DossierProxy(); // subclass, same MaxDepth metadata
$c = new Dossier();
$a->linkedDossiers = $b;
$b->linkedDossiers = $c;
$normalizer->normalize($a, null, ['enable_max_depth' => true]);
// before: A → B → C
// after: A → B
Commits
-------
3a040d0 [Serializer] Fix max depth counting for subclasses that inherit MaxDepth metadata4 files changed
+87-1Lines changed: 87 additions & 1 deletion
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- src/Symfony/Component/Serializer
- Normalizer
- Tests
- Fixtures/Attributes
- Normalizer/Features
Expand file treeCollapse file tree
Open diff view settings
Collapse file
src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php+12-1Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
762 | 762 | |
763 | 763 | |
764 | 764 | |
765 | | - |
| 765 | + |
| 766 | + |
| 767 | + |
| 768 | + |
| 769 | + |
| 770 | + |
| 771 | + |
| 772 | + |
| 773 | + |
| 774 | + |
| 775 | + |
| 776 | + |
766 | 777 | |
767 | 778 | |
768 | 779 | |
|
Collapse file
src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/MaxDepthRecursiveDummy.php
Copy file name to clipboard+32Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
Collapse file
src/Symfony/Component/Serializer/Tests/Fixtures/Attributes/MaxDepthRecursiveDummyProxy.php
Copy file name to clipboard+16Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
Collapse file
src/Symfony/Component/Serializer/Tests/Normalizer/Features/MaxDepthTestTrait.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/Features/MaxDepthTestTrait.php+27Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
13 | 13 | |
14 | 14 | |
15 | 15 | |
| 16 | + |
| 17 | + |
16 | 18 | |
17 | 19 | |
18 | 20 | |
| ||
60 | 62 | |
61 | 63 | |
62 | 64 | |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
63 | 90 | |
64 | 91 | |
65 | 92 | |
|
0 commit comments