2424class SimpleNormalizer
2525{
2626 private readonly ?ClassMetadataFactory $ doctrineMetadata ;
27- private const string STACK_CONTEXT = "simple-normalizer.debug-stack " ;
2827 private const int DEFAULT_MAX_DEPTH = 128 ;
2928
3029 /** @var array<class-string, class-string> */
@@ -53,7 +52,7 @@ public function __construct (
5352 */
5453 public function normalize (mixed $ value , array $ context = []) : mixed
5554 {
56- $ stack = $ this -> extractInitialStack ( $ context ) ;
55+ $ stack = [] ;
5756 $ normalizedValue = $ this ->recursiveNormalize ($ value , $ context , $ stack );
5857
5958 if ($ this ->isDebug )
@@ -68,7 +67,7 @@ public function normalize (mixed $value, array $context = []) : mixed
6867 */
6968 public function normalizeArray (array $ array , array $ context = []) : array
7069 {
71- $ stack = $ this -> extractInitialStack ( $ context ) ;
70+ $ stack = [] ;
7271 $ normalizedValue = $ this ->recursiveNormalizeArray ($ array , $ context , $ stack );
7372
7473 if ($ this ->isDebug )
@@ -86,7 +85,7 @@ public function normalizeArray (array $array, array $context = []) : array
8685 public function normalizeMap (array $ array , array $ context = []) : array |\stdClass
8786 {
8887 // return stdClass if the array is empty here, as it will be automatically normalized to `{}` in JSON.
89- $ stack = $ this -> extractInitialStack ( $ context ) ;
88+ $ stack = [] ;
9089 $ normalizedValue = $ this ->recursiveNormalizeArray ($ array , $ context , $ stack ) ?: new \stdClass ();
9190
9291 if ($ this ->isDebug )
@@ -144,9 +143,6 @@ private function recursiveNormalize (mixed $value, array $context, array &$stack
144143 $ normalizer = $ this ->objectNormalizers ->get ($ className );
145144 \assert ($ normalizer instanceof SimpleObjectNormalizerInterface);
146145
147- // Preserve debug stack visibility for custom object normalizers.
148- $ context [self ::STACK_CONTEXT ] = $ stack ;
149-
150146 return $ normalizer ->normalize ($ value , $ context , $ this );
151147 }
152148 catch (ServiceNotFoundException $ exception )
@@ -229,25 +225,4 @@ private function recursiveNormalizeArray (array $array, array $context, array &$
229225
230226 return $ result ;
231227 }
232-
233- /**
234- * @return list<string>
235- */
236- private function extractInitialStack (array $ context ) : array
237- {
238- if (!isset ($ context [self ::STACK_CONTEXT ]) || !\is_array ($ context [self ::STACK_CONTEXT ]))
239- {
240- return [];
241- }
242-
243- $ stack = [];
244-
245- foreach ($ context [self ::STACK_CONTEXT ] as $ entry )
246- {
247- \assert (\is_string ($ entry ));
248- $ stack [] = $ entry ;
249- }
250-
251- return $ stack ;
252- }
253228}
0 commit comments