ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Slim\Handlers\NotFound Class Reference

Default Slim application not found handler. More...

+ Inheritance diagram for Slim\Handlers\NotFound:
+ Collaboration diagram for Slim\Handlers\NotFound:

Public Member Functions

 __invoke (ServerRequestInterface $request, ResponseInterface $response)
 Invoke not found handler. More...
 

Protected Member Functions

 renderPlainNotFoundOutput ()
 Render plain not found message. More...
 
 renderJsonNotFoundOutput ()
 Return a response for application/json content not found. More...
 
 renderXmlNotFoundOutput ()
 Return a response for xml content not found. More...
 
 renderHtmlNotFoundOutput (ServerRequestInterface $request)
 Return a response for text/html content not found. More...
 
- Protected Member Functions inherited from Slim\Handlers\AbstractHandler
 determineContentType (ServerRequestInterface $request)
 Determine which content type we know about is wanted using Accept header. More...
 

Additional Inherited Members

- Protected Attributes inherited from Slim\Handlers\AbstractHandler
 $knownContentTypes
 

Detailed Description

Default Slim application not found handler.

It outputs a simple message in either JSON, XML or HTML based on the Accept header.

Definition at line 22 of file NotFound.php.

Member Function Documentation

◆ __invoke()

Slim\Handlers\NotFound::__invoke ( ServerRequestInterface  $request,
ResponseInterface  $response 
)

Invoke not found handler.

Parameters
ServerRequestInterface$requestThe most recent Request object
ResponseInterface$responseThe most recent Response object
Returns
ResponseInterface
Exceptions
UnexpectedValueException

Definition at line 33 of file NotFound.php.

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 }
determineContentType(ServerRequestInterface $request)
Determine which content type we know about is wanted using Accept header.
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
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output
getMethod()
Retrieves the HTTP method of the 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
$response

References $contentType, $output, $response, Slim\Handlers\AbstractHandler\determineContentType(), Psr\Http\Message\RequestInterface\getMethod(), Slim\Handlers\NotFound\renderHtmlNotFoundOutput(), Slim\Handlers\NotFound\renderJsonNotFoundOutput(), Slim\Handlers\NotFound\renderPlainNotFoundOutput(), and Slim\Handlers\NotFound\renderXmlNotFoundOutput().

+ Here is the call graph for this function:

◆ renderHtmlNotFoundOutput()

Slim\Handlers\NotFound::renderHtmlNotFoundOutput ( ServerRequestInterface  $request)
protected

Return a response for text/html content not found.

Parameters
ServerRequestInterface$requestThe most recent Request object
Returns
ResponseInterface

Definition at line 104 of file NotFound.php.

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 }
html()
getUri()
Retrieves the URI instance.

References Psr\Http\Message\RequestInterface\getUri(), and html().

Referenced by Slim\Handlers\NotFound\__invoke().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderJsonNotFoundOutput()

Slim\Handlers\NotFound::renderJsonNotFoundOutput ( )
protected

Return a response for application/json content not found.

Returns
ResponseInterface

Definition at line 82 of file NotFound.php.

83 {
84 return '{"message":"Not found"}';
85 }

Referenced by Slim\Handlers\NotFound\__invoke().

+ Here is the caller graph for this function:

◆ renderPlainNotFoundOutput()

Slim\Handlers\NotFound::renderPlainNotFoundOutput ( )
protected

Render plain not found message.

Returns
ResponseInterface

Definition at line 72 of file NotFound.php.

73 {
74 return 'Not found';
75 }

Referenced by Slim\Handlers\NotFound\__invoke().

+ Here is the caller graph for this function:

◆ renderXmlNotFoundOutput()

Slim\Handlers\NotFound::renderXmlNotFoundOutput ( )
protected

Return a response for xml content not found.

Returns
ResponseInterface

Definition at line 92 of file NotFound.php.

93 {
94 return '<root><message>Not found</message></root>';
95 }

Referenced by Slim\Handlers\NotFound\__invoke().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: