/** * Redirects the request back to the referrer * * @access public * @return ServiceProvider */ public function back() { $referer = $this->request->server()->get('HTTP_REFERER'); if (null !== $referer) { return $this->response->redirect($referer); } $this->refresh(); return $this; }
/** * Routes an exception through the error callbacks * * @param Exception $err The exception that occurred * @throws UnhandledException If the error/exception isn't handled by an error callback * @access protected * @return void */ protected function error(Exception $err) { $type = get_class($err); $msg = $err->getMessage(); if (count($this->errorCallbacks) > 0) { foreach (array_reverse($this->errorCallbacks) as $callback) { if (is_callable($callback)) { if (is_string($callback)) { $callback($this, $msg, $type, $err); return; } else { call_user_func($callback, $this, $msg, $type, $err); return; } } else { if (null !== $this->response) { $this->response->redirect($callback); } } } } else { $this->response->code(500); throw new UnhandledException($err); } // Lock our response, since we probably don't want // anything else messing with our error code/body $this->response->lock(); }
public function testRedirect() { $url = 'http://google.com/'; $code = 302; $response = new Response(); $response->redirect($url, $code); $this->assertSame($code, $response->code()); $this->assertSame($url, $response->headers()->get('location')); $this->assertTrue($response->isLocked()); }
/** * Routes an exception through the error callbacks * * @param Exception $err The exception that occurred * @access protected * @return void */ protected function error(Exception $err) { $type = get_class($err); $msg = $err->getMessage(); if (count($this->errorCallbacks) > 0) { foreach (array_reverse($this->errorCallbacks) as $callback) { if (is_callable($callback)) { if (is_string($callback)) { if ($callback($this, $msg, $type, $err)) { return; } } else { if (call_user_func($callback, $this, $msg, $type, $err)) { return; } } } else { if (null !== $this->service && null !== $this->response) { $this->service->flash($err); $this->response->redirect($callback); } } } } else { $this->response->code(500); throw new UnhandledException($err); } }