ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
NotFound.php
Go to the documentation of this file.
1<?php
9namespace Slim\Handlers;
10
14use UnexpectedValueException;
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>
139END;
140 }
141}
html()
An exception for terminatinating execution or to throw for unit testing.
Abstract Slim application handler.
determineContentType(ServerRequestInterface $request)
Determine which content type we know about is wanted using Accept header.
Default Slim application not found handler.
Definition: NotFound.php:23
renderXmlNotFoundOutput()
Return a response for xml content not found.
Definition: NotFound.php:92
renderHtmlNotFoundOutput(ServerRequestInterface $request)
Return a response for text/html content not found.
Definition: NotFound.php:104
renderJsonNotFoundOutput()
Return a response for application/json content not found.
Definition: NotFound.php:82
renderPlainNotFoundOutput()
Render plain not found message.
Definition: NotFound.php:72
__invoke(ServerRequestInterface $request, ResponseInterface $response)
Invoke not found handler.
Definition: NotFound.php:33
Body.
Definition: Body.php:20
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
getUri()
Retrieves the URI instance.
getMethod()
Retrieves the HTTP method of the request.
Representation of an outgoing, server-side response.
Representation of an incoming, server-side HTTP request.
if( $path[strlen( $path) - 1]==='/') if(is_dir($path)) if(!file_exists( $path)) if(preg_match('#\.php$#D', $path)) $contentType
Definition: module.php:142
Slim Framework (https://slimframework.com)
$response