protected function matchesTypehint($handler, Exception $exception)
{
if ($handler instanceof ErrorHandlerInterface) {
return true;
}
if (is_array($handler)) {
$reflection = new ReflectionMethod($handler[0], $handler[1]);
} else {
$reflection = new ReflectionFunction($handler);
}
$params = $reflection->getParameters();
// if the handler takes no parameters it is considered global and should
// handle every exception
if (empty($params)) {
return true;
}
$handlerHint = $params[0]->getClass();
// likewise, if the first handler parameter has no typehint, consider it
// a global handler that handles everything
if (!$handlerHint) {
return true;
}
return $handlerHint->isInstance($exception);
}