ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.

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

34  {
35  if ($request->getMethod() === 'OPTIONS') {
36  $contentType = 'text/plain';
38  } else {
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':
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  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
renderJsonNotFoundOutput()
Return a response for application/json content not found.
Definition: NotFound.php:82
determineContentType(ServerRequestInterface $request)
Determine which content type we know about is wanted using Accept header.
renderPlainNotFoundOutput()
Render plain not found message.
Definition: NotFound.php:72
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
$response
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
+ 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.

References Sabre\Event\Promise\all(), Psr\Http\Message\RequestInterface\getUri(), html(), and size.

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

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  }
foreach($paths as $path) $request
Definition: asyncclient.php:32
"color:#CC0000 style
Definition: example_001.php:92
all(array $promises)
This file contains a set of functions that are useful for dealing with the Promise object...
Definition: functions.php:32
font size
Definition: langcheck.php:162
html()
+ 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.

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

83  {
84  return '{"message":"Not found"}';
85  }
+ 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.

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

73  {
74  return 'Not found';
75  }
+ 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.

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

93  {
94  return '<root><message>Not found</message></root>';
95  }
+ Here is the caller graph for this function:

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