public function Fast404::response in Fast 404 8.2
Same name and namespace in other branches
- 8 src/Fast404.php \Drupal\fast404\Fast404::response()
Prepare a 404 response.
Parameters
bool $return: Decide whether to return the response object or simply send it.
Return value
\Symfony\Component\HttpFoundation\Response If this returns anything, it will be a response object.
File
- src/
Fast404.php, line 198
Class
- Fast404
- Fast404: A value object for manager Fast 404 logic.
Namespace
Drupal\fast404Code
public function response($return = FALSE) {
$message = Settings::get('fast404_html', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL "@path" was not found on this server.</p></body></html>');
$return_gone = Settings::get('fast404_return_gone', FALSE);
$custom_404_path = Settings::get('fast404_HTML_error_page', FALSE);
// If a file is set to provide us with Fast 404 joy, load it.
if (($this->loadHtml || Settings::get('fast404_HTML_error_all_paths', FALSE) === TRUE) && file_exists($custom_404_path)) {
$message = @file_get_contents($custom_404_path, FALSE);
}
$headers = [
Settings::get('fast404_HTTP_status_method', 'mod_php') === 'FastCGI' ? 'Status:' : 'HTTP/1.0' => $return_gone ? '410 Gone' : '404 Not Found',
];
$response = new Response(new FormattableMarkup($message, [
'@path' => $this->request
->getPathInfo(),
]), $return_gone ? 410 : 404, $headers);
if ($return) {
return $response;
}
$response
->send();
throw new ServiceUnavailableHttpException(3, 'The requested URL "@path" was not found on this server. Try again shortly.', [
'@path' => $this->request
->getPathInfo(),
]);
}