/** * @{inheritdoc} */ public function prepare(Request $request) { if ('1.0' != $request->server->get('SERVER_PROTOCOL')) { $this->setProtocolVersion('1.1'); } $this->headers->set('Cache-Control', 'no-cache'); parent::prepare($request); }
/** * Test the Response::prepare method. * * @group laravel */ public function testPrepareMethodCreatesAResponseInstanceFromGivenValue() { $response = Response::prepare('Taylor'); $this->assertInstanceOf('Laravel\\Response', $response); $this->assertEquals('Taylor', $response->content); $response = Response::prepare(new Response('Taylor')); $this->assertInstanceOf('Laravel\\Response', $response); $this->assertEquals('Taylor', $response->content); }
/** * Handle an exception and display the exception report. * * @param Exception $exception * @return void */ public static function exception($exception) { static::log($exception); // If detailed errors are enabled, we'll just format the exception into // a simple error message and display it on the screen. We don't use a // View in case the problem is in the View class. if (Config::get('error.detail')) { echo "<html><h2>Unhandled Exception</h2>\n\t\t\t\t <h3>Message:</h3>\n\t\t\t\t <pre>" . $exception->getMessage() . "</pre>\n\t\t\t\t <h3>Location:</h3>\n\t\t\t\t <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n\t\t\t\t <h3>Stack Trace:</h3>\n\t\t\t\t <pre>" . $exception->getTraceAsString() . "</pre></html>"; } else { $response = Event::first('500'); return Response::prepare($response)->send(); } exit(1); }
/** * {@inheritdoc} */ public function prepare(Request $request) { $this->headers->set('Cache-Control', 'no-cache'); return parent::prepare($request); }
// Call the "before" filter for the application and module. // -------------------------------------------------------------- foreach (array('before', ACTIVE_MODULE . '::before') as $filter) { $response = Routing\Filter::call($filter, array(Request::method(), Request::uri()), true); if (!is_null($response)) { break; } } // -------------------------------------------------------------- // Route the request and get the response from the route. // -------------------------------------------------------------- if (is_null($response)) { $route = Routing\Router::make(Request::method(), Request::uri(), new Routing\Loader(ACTIVE_MODULE_PATH))->route(); $response = is_null($route) ? Response::error('404') : $route->call(); } $response = Response::prepare($response); // -------------------------------------------------------------- // Call the "after" filter for the application and module. // -------------------------------------------------------------- foreach (array(ACTIVE_MODULE . '::after', 'after') as $filter) { Routing\Filter::call($filter, array($response, Request::method(), Request::uri())); } // -------------------------------------------------------------- // Stringify the response. // -------------------------------------------------------------- $response->content = (string) $response->content; // -------------------------------------------------------------- // Close the session. // -------------------------------------------------------------- if (Config::get('session.driver') != '') { Session::close();
/** * Handle an exception and display the exception report. * * @param Exception $exception * @param bool $trace * @return void */ public static function exception($exception, $trace = true) { static::log($exception); ob_get_level() and ob_end_clean(); $message = $exception->getMessage(); // For Laravel view errors we want to show a prettier error: $file = $exception->getFile(); if (str_contains($exception->getFile(), 'eval()') and str_contains($exception->getFile(), 'laravel' . DS . 'view.php')) { $message = 'Error rendering view: [' . View::$last['name'] . ']' . PHP_EOL . PHP_EOL . $message; $file = View::$last['path']; } // If detailed errors are enabled, we'll just format the exception into // a simple error message and display it on the screen. We don't use a // View in case the problem is in the View class. if (Config::get('error.detail')) { $response_body = "<html><h2>Unhandled Exception</h2>\n\t\t\t\t<h3>Message:</h3>\n\t\t\t\t<pre>" . $message . "</pre>\n\t\t\t\t<h3>Location:</h3>\n\t\t\t\t<pre>" . $file . " on line " . $exception->getLine() . "</pre>"; if ($trace) { $response_body .= "\n\t\t\t\t <h3>Stack Trace:</h3>\n\t\t\t\t <pre>" . $exception->getTraceAsString() . "</pre></html>"; } $response = Response::make($response_body, 500); } else { $response = Event::first('500', array($exception)); $response = Response::prepare($response); } $response->render(); $response->send(); $response->foundation->finish(); exit(1); }