/**
  * Handle the given request and response in the case of a routing error.
  * 
  * @param Request  $request
  * @param Response $response
  * @return mixed
  */
 public function handle(Request $request, Response $response)
 {
     $status = $response->status();
     $response->content("{$status} error.");
     if ($this->view->exists("errors/{$status}")) {
         $response->content($this->view->create("errors/{$status}", array('http_host' => $request->host(), 'request_uri' => $request->path(), 'signature' => $request->server('server_signature'))));
     }
     return $response;
 }
Beispiel #2
0
 /**
  * Dispatch the given request and response objects with the given callable
  * and optional arguments.
  * 
  * An error handler can be set (@see Router::setErrorHandler()) to handle
  * the request in the case that the given action is not callable.
  * 
  * @param Request         $request
  * @param Response        $response
  * @param callable|string $callable
  * @param array           $arguments [optional]
  * @return Response
  */
 protected function dispatchCallable(Request $request, Response $response, $callable, array $arguments = array())
 {
     $requestResponse = array($request, $response);
     $responses = $this->event('router.before', $requestResponse);
     if (is_callable($callable)) {
         $responses[] = $requestResponse[1] = $this->call($callable, $arguments);
     } else {
         $response->status(404);
         return $this->handleError($request, $response, 'Non-callable resolved from the matched route');
     }
     $responses = array_merge($responses, $this->event('router.after', $requestResponse));
     $requestResponse[1] = $responses[count($responses) - 1];
     $responses = array_merge($responses, $this->event('router.last', $requestResponse));
     foreach ($responses as $potential) {
         $potential = static::prepareResponse($potential);
         if ($potential->redirected() || $potential->hasContent()) {
             return $potential;
         }
     }
     return $response;
 }