$input->getMessage(), 'trace' => $input->getTrace() ]; $input = $newinput; } if (is_object($input)) { $input = $this->processObject($input); } if (is_array($input)) { return $this->checkArrayForSensitiveData($input); } if (($json = json_decode($input, true)) && is_array($json)) { $json = $this->checkForSensitiveData($json); return json_encode($json); } return $input; } /** * Convert object to array * * @param \stdClass $input * @return array */ private function processObject($input) { if (method_exists($input, 'toArray')) { return $input->toArray(); } if (method_exists($input, 'getData')) { return $input->getData(); } return get_object_vars($input); } /** * Recursively search array for sensitive data and replace it if found * * @param array $input * @return array */ public function checkArrayForSensitiveData($input) { foreach ($input as $key => $value) { if (is_int($key)) { continue; } if (in_array($key, $this->privateKeys)) { $input[$key] = $this->replaceValue; continue; } if (!is_array($value)) { continue; } foreach ($value as $k => $v) { $input[$key][$k] = $this->checkForSensitiveData($v); } } return $input; } }