ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
NotFound.php
Go to the documentation of this file.
1 <?php
9 namespace Slim\Handlers;
10 
13 use Slim\Http\Body;
15 
23 {
34  {
35  if ($request->getMethod() === 'OPTIONS') {
36  $contentType = 'text/plain';
38  } else {
39  $contentType = $this->determineContentType($request);
40  switch ($contentType) {
41  case 'application/json':
43  break;
44 
45  case 'text/xml':
46  case 'application/xml':
48  break;
49 
50  case 'text/html':
51  $output = $this->renderHtmlNotFoundOutput($request);
52  break;
53 
54  default:
55  throw new UnexpectedValueException('Cannot render unknown content type ' . $contentType);
56  }
57  }
58 
59  $body = new Body(fopen('php://temp', 'r+'));
60  $body->write($output);
61 
62  return $response->withStatus(404)
63  ->withHeader('Content-Type', $contentType)
64  ->withBody($body);
65  }
66 
72  protected function renderPlainNotFoundOutput()
73  {
74  return 'Not found';
75  }
76 
82  protected function renderJsonNotFoundOutput()
83  {
84  return '{"message":"Not found"}';
85  }
86 
92  protected function renderXmlNotFoundOutput()
93  {
94  return '<root><message>Not found</message></root>';
95  }
96 
105  {
106  $homeUrl = (string)($request->getUri()->withPath('')->withQuery('')->withFragment(''));
107  return <<<END
108 <html>
109  <head>
110  <title>Page Not Found</title>
111  <style>
112  body{
113  margin:0;
114  padding:30px;
115  font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;
116  }
117  h1{
118  margin:0;
119  font-size:48px;
120  font-weight:normal;
121  line-height:48px;
122  }
123  strong{
124  display:inline-block;
125  width:65px;
126  }
127  </style>
128  </head>
129  <body>
130  <h1>Page Not Found</h1>
131  <p>
132  The page you are looking for could not be found. Check the address bar
133  to ensure your URL is spelled correctly. If all else fails, you can
134  visit our home page at the link below.
135  </p>
136  <a href='$homeUrl'>Visit the Home Page</a>
137  </body>
138 </html>
139 END;
140  }
141 }
getMethod()
Retrieves the HTTP method of the request.
Representation of an incoming, server-side HTTP request.
foreach($paths as $path) $request
Definition: asyncclient.php:32
withStatus($code, $reasonPhrase='')
Return an instance with the specified status code and, optionally, reason phrase. ...
renderJsonNotFoundOutput()
Return a response for application/json content not found.
Definition: NotFound.php:82
"color:#CC0000 style
Definition: example_001.php:92
determineContentType(ServerRequestInterface $request)
Determine which content type we know about is wanted using Accept header.
all(array $promises)
This file contains a set of functions that are useful for dealing with the Promise object...
Definition: functions.php:32
getUri()
Retrieves the URI instance.
__invoke(ServerRequestInterface $request, ResponseInterface $response)
Invoke not found handler.
Definition: NotFound.php:33
Representation of an outgoing, server-side response.
renderPlainNotFoundOutput()
Render plain not found message.
Definition: NotFound.php:72
Default Slim application not found handler.
Definition: NotFound.php:22
font size
Definition: langcheck.php:162
html()
Body.
Definition: Body.php:19
if($path[strlen($path) - 1]==='/') if(is_dir($path)) if(!file_exists($path)) if(preg_match('#\.php$#D', mb_strtolower($path, 'UTF-8'))) $contentType
Definition: module.php:144
Slim Framework (https://slimframework.com)
$response
renderXmlNotFoundOutput()
Return a response for xml content not found.
Definition: NotFound.php:92
Abstract Slim application handler.
renderHtmlNotFoundOutput(ServerRequestInterface $request)
Return a response for text/html content not found.
Definition: NotFound.php:104