@@ -293,7 +293,7 @@ protected function collectVars(Throwable $exception, int $statusCode): array
293293 $ trace = $ exception ->getTrace ();
294294
295295 if ($ this ->config ->sensitiveDataInTrace !== []) {
296- $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
296+ $ trace = $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
297297 }
298298
299299 return [
@@ -311,31 +311,52 @@ protected function collectVars(Throwable $exception, int $statusCode): array
311311 * Mask sensitive data in the trace.
312312 *
313313 * @param array|object $trace
314+ *
315+ * @return array|object
314316 */
315- protected function maskSensitiveData (&$ trace , array $ keysToMask , string $ path = '' )
317+ protected function maskSensitiveData ($ trace , array $ keysToMask , string $ path = '' )
318+ {
319+ foreach ($ trace as $ i => $ line ) {
320+ $ trace [$ i ]['args ' ] = $ this ->maskData ($ line ['args ' ], $ keysToMask );
321+ }
322+
323+ return $ trace ;
324+ }
325+
326+ /**
327+ * @param array|object $args
328+ *
329+ * @return array|object
330+ */
331+ private function maskData ($ args , array $ keysToMask , string $ path = '' )
316332 {
317333 foreach ($ keysToMask as $ keyToMask ) {
318334 $ explode = explode ('/ ' , $ keyToMask );
319335 $ index = end ($ explode );
320336
321337 if (strpos (strrev ($ path . '/ ' . $ index ), strrev ($ keyToMask )) === 0 ) {
322- if (is_array ($ trace ) && array_key_exists ($ index , $ trace )) {
323- $ trace [$ index ] = '****************** ' ;
324- } elseif (is_object ($ trace ) && property_exists ($ trace , $ index ) && isset ($ trace ->{$ index })) {
325- $ trace ->{$ index } = '****************** ' ;
338+ if (is_array ($ args ) && array_key_exists ($ index , $ args )) {
339+ $ args [$ index ] = '****************** ' ;
340+ } elseif (
341+ is_object ($ args ) && property_exists ($ args , $ index )
342+ && isset ($ args ->{$ index }) && is_scalar ($ args ->{$ index })
343+ ) {
344+ $ args ->{$ index } = '****************** ' ;
326345 }
327346 }
328347 }
329348
330- if (is_object ( $ trace )) {
331- $ trace = get_object_vars ( $ trace );
332- }
333-
334- if ( is_array ( $ trace )) {
335- foreach ($ trace as $ pathKey => $ subarray ) {
336- $ this ->maskSensitiveData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
349+ if (is_array ( $ args )) {
350+ foreach ( $ args as $ pathKey => $ subarray ) {
351+ $ args [ $ pathKey ] = $ this -> maskData ( $ subarray , $ keysToMask , $ path . ' / ' . $ pathKey );
352+ }
353+ } elseif ( is_object ( $ args )) {
354+ foreach ($ args as $ pathKey => $ subarray ) {
355+ $ args ->{ $ pathKey } = $ this ->maskData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
337356 }
338357 }
358+
359+ return $ args ;
339360 }
340361
341362 /**
0 commit comments