8000 minor #60025 [Serializer] Fix code skipped by premature return (HypeMC) · symfony/symfony@8b43964 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b43964

Browse files
minor #60025 [Serializer] Fix code skipped by premature return (HypeMC)
This PR was merged into the 6.4 branch. Discussion ---------- [Serializer] Fix code skipped by premature return | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT The problem with the current code is the early return: https://github.com/symfony/symfony/blob/c9ed7620fb00e8e7db89fe724cabd0bd43cec0dc/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L2007-L2009 Some code after the return is not related to the object normalizer, and should therefor not be skipped: https://github.com/symfony/symfony/blob/c9ed7620fb00e8e7db89fe724cabd0bd43cec0dc/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L2025-L2026 This PR replaces the early return by wrapping the code related to the object normalizer inside the `if` block to prevent any future mistakes. Probably easier to review with [whitespace changes hidden](https://github.com/symfony/symfony/pull/60025/files?diff=unified&w=1). Commits ------- 1aec1b3 [Serializer] Fix code skipped by premature return
2 parents 3df7170 + 1aec1b3 commit 8b43964

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,24 +2004,22 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
20042004
$container->setParameter('serializer.default_context', $defaultContext);
20052005
}
20062006

2007-
if (!$container->hasDefinition('serializer.normalizer.object')) {
2008-
return;
2009-
}
2007+
if ($container->hasDefinition('serializer.normalizer.object')) {
2008+
$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
2009+
$context = $arguments[6] ?? $defaultContext;
20102010

2011-
$arguments = $container->getDefinition('serializer.normalizer.object')->getArguments();
2012-
$context = $arguments[6] ?? $defaultContext;
2011+
if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
2012+
$context += ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
2013+
$container->getDefinition('serializer.normalizer.object')->setArgument(5, null);
2014+
}
20132015

2014-
if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {
2015-
$context += ['circular_reference_handler' => new Reference($config['circular_reference_handler'])];
2016-
$container->getDefinition('serializer.normalizer.object')->setArgument(5, null);
2017-
}
2016+
if ($config['max_depth_handler'] ?? false) {
2017+
$context += ['max_depth_handler' => new Reference($config['max_depth_handler'])];
2018+
}
20182019

2019-
if ($config['max_depth_handler'] ?? false) {
2020-
$context += ['max_depth_handler' => new Reference($config['max_depth_handler'])];
2020+
$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
20212021
}
20222022

2023-
$container->getDefinition('serializer.normalizer.object')->setArgument(6, $context);
2024-
20252023
$container->getDefinition('serializer.normalizer.property')->setArgument(5, $defaultContext);
20262024
}
20272025

0 commit comments

Comments
 (0)
0