Autarky\Errors\ErrorHandlerManager::matchesTypehint PHP Method

matchesTypehint() protected method

Check if a handler's argument typehint matches an exception.
protected matchesTypehint ( callable | Autarky\Errors\ErrorHandlerInterface $handler, Exception $exception ) : boolean
$handler callable | Autarky\Errors\ErrorHandlerInterface
$exception Exception
return boolean
    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);
    }