Autarky\Errors\HandlerResolver::resolve PHP Method

resolve() public method

Resolve a handler.
public resolve ( mixed $handler ) : Autarky\Errors\ErrorHandlerInterface | callable
$handler mixed
return Autarky\Errors\ErrorHandlerInterface | callable
    public function resolve($handler)
    {
        if (!is_string($handler)) {
            return $handler;
        }
        $handler = $this->container->resolve($handler);
        if (!is_callable($handler) && !$handler instanceof ErrorHandlerInterface) {
            $type = is_object($handler) ? get_class($handler) : gettype($handler);
            throw new \UnexpectedValueException("Resolved error handler is not a valid handler - must be callable or an instance of Autarky\\Errors\\ErrorHandlerInterface, {$type} given");
        }
        return $handler;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function handle(Exception $exception)
 {
     if ($this->rethrow) {
         throw $exception;
     }
     foreach ($this->handlers as $index => $handler) {
         try {
             if (is_string($handler)) {
                 $handler = $this->resolver->resolve($handler);
                 $this->handlers->offsetSet($index, $handler);
             } else {
                 if (is_array($handler) && is_string($handler[0])) {
                     $handler[0] = $this->resolver->resolve($handler[0]);
                     $this->handlers->offsetSet($index, $handler);
                 }
             }
             if (!$this->matchesTypehint($handler, $exception)) {
                 continue;
             }
             $result = $this->callHandler($handler, $exception);
             if ($result !== null) {
                 return $this->makeResponse($result, $exception);
             }
         } catch (Exception $newException) {
             return $this->handle($newException);
         }
     }
     return $this->makeResponse($this->defaultHandler->handle($exception), $exception);
 }
HandlerResolver