@@ -70,7 +70,7 @@ protected function collectVars(Throwable $exception, int $statusCode): array
7070 $ trace = $ exception ->getTrace ();
7171
7272 if ($ this ->config ->sensitiveDataInTrace !== []) {
73- $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
73+ $ trace = $ this ->maskSensitiveData ($ trace , $ this ->config ->sensitiveDataInTrace );
7474 }
7575
7676 return [
@@ -89,30 +89,49 @@ protected function collectVars(Throwable $exception, int $statusCode): array
8989 *
9090 * @param array|object $trace
9191 */
92- protected function maskSensitiveData (&$ trace , array $ keysToMask , string $ path = '' ): void
92+ protected function maskSensitiveData ($ trace , array $ keysToMask , string $ path = '' )
93+ {
94+ foreach ($ trace as $ i => $ line ) {
95+ $ trace [$ i ]['args ' ] = $ this ->maskData ($ line ['args ' ], $ keysToMask );
96+ }
97+
98+ return $ trace ;
99+ }
100+
101+ /**
102+ * @param array|object $args
103+ *
104+ * @return array|object
105+ */
106+ private function maskData ($ args , array $ keysToMask , string $ path = '' )
93107 {
94108 foreach ($ keysToMask as $ keyToMask ) {
95109 $ explode = explode ('/ ' , $ keyToMask );
96110 $ index = end ($ explode );
97111
98112 if (strpos (strrev ($ path . '/ ' . $ index ), strrev ($ keyToMask )) === 0 ) {
99- if (is_array ($ trace ) && array_key_exists ($ index , $ trace )) {
100- $ trace [$ index ] = '****************** ' ;
101- } elseif (is_object ($ trace ) && property_exists ($ trace , $ index ) && isset ($ trace ->{$ index })) {
102- $ trace ->{$ index } = '****************** ' ;
113+ if (is_array ($ args ) && array_key_exists ($ index , $ args )) {
114+ $ args [$ index ] = '****************** ' ;
115+ } elseif (
116+ is_object ($ args ) && property_exists ($ args , $ index )
117+ && isset ($ args ->{$ index }) && is_scalar ($ args ->{$ index })
118+ ) {
119+ $ args ->{$ index } = '****************** ' ;
103120 }
104121 }
105122 }
106123
107- if (is_object ( $ trace )) {
108- $ trace = get_object_vars ( $ trace );
109- }
110-
111- if ( is_array ( $ trace )) {
112- foreach ($ trace as $ pathKey => $ subarray ) {
113- $ this ->maskSensitiveData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
124+ if (is_array ( $ args )) {
125+ foreach ( $ args as $ pathKey => $ subarray ) {
126+ $ args [ $ pathKey ] = $ this -> maskData ( $ subarray , $ keysToMask , $ path . ' / ' . $ pathKey );
127+ }
128+ } elseif ( is_object ( $ args )) {
129+ foreach ($ args as $ pathKey => $ subarray ) {
130+ $ args ->{ $ pathKey } = $ this ->maskData ($ subarray , $ keysToMask , $ path . '/ ' . $ pathKey );
114131 }
115132 }
133+
134+ return $ args ;
116135 }
117136
118137 /**
0 commit comments