Last active
September 5, 2016 12:38
-
-
Save wallacemaxters/713abef172b03a18e44954157eb8f933 to your computer and use it in GitHub Desktop.
Simplify the Trace of an exception. Object references are converted to class string name.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Simplify the Trace of an exception. Object references are converted to class string name. | |
* | |
* @param Exception|Throwable $e | |
* @throws \InvalidArgumentException | |
* @return array | |
* */ | |
function simple_exception_trace($e) | |
{ | |
if ($e instanceof \Exception || $e instanceof \Throwable) { | |
$recursiveObjectName = function ($value) use (&$recursiveObjectName) { | |
if (is_array($value)) { | |
return array_map($recursiveObjectName, $value); | |
} | |
return is_object($value) ? get_class($value) : $value; | |
}; | |
$trace = $e->getTrace(); | |
foreach ($trace as &$line) { | |
isset($line['args']) && $line = $recursiveObjectName($line); | |
} | |
return $trace; | |
} | |
throw new \InvalidArgumentException('Invalid argument. Expected "Exception" or "Throwable" instance'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment