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

Default Slim application not allowed handler. More...

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

Public Member Functions

 __invoke (ServerRequestInterface $request, ResponseInterface $response, array $methods)
 Invoke error handler. More...
 

Protected Member Functions

 renderPlainOptionsMessage ($methods)
 Render PLAIN message for OPTIONS response. More...
 
 renderJsonNotAllowedMessage ($methods)
 Render JSON not allowed message. More...
 
 renderXmlNotAllowedMessage ($methods)
 Render XML not allowed message. More...
 
 renderHtmlNotAllowedMessage ($methods)
 Render HTML not allowed message. 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 allowed handler.

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

Definition at line 22 of file NotAllowed.php.

Member Function Documentation

◆ __invoke()

Slim\Handlers\NotAllowed::__invoke ( ServerRequestInterface  $request,
ResponseInterface  $response,
array  $methods 
)

Invoke error handler.

Parameters
ServerRequestInterface$requestThe most recent Request object
ResponseInterface$responseThe most recent Response object
string[]$methods Allowed HTTP methods
Returns
ResponseInterface
Exceptions
UnexpectedValueException

Definition at line 34 of file NotAllowed.php.

References $contentType, $output, Slim\Handlers\AbstractHandler\determineContentType(), Psr\Http\Message\RequestInterface\getMethod(), Slim\Handlers\NotAllowed\renderHtmlNotAllowedMessage(), Slim\Handlers\NotAllowed\renderJsonNotAllowedMessage(), Slim\Handlers\NotAllowed\renderPlainOptionsMessage(), Slim\Handlers\NotAllowed\renderXmlNotAllowedMessage(), and Psr\Http\Message\ResponseInterface\withStatus().

35  {
36  if ($request->getMethod() === 'OPTIONS') {
37  $status = 200;
38  $contentType = 'text/plain';
39  $output = $this->renderPlainOptionsMessage($methods);
40  } else {
41  $status = 405;
42  $contentType = $this->determineContentType($request);
43  switch ($contentType) {
44  case 'application/json':
45  $output = $this->renderJsonNotAllowedMessage($methods);
46  break;
47 
48  case 'text/xml':
49  case 'application/xml':
50  $output = $this->renderXmlNotAllowedMessage($methods);
51  break;
52 
53  case 'text/html':
54  $output = $this->renderHtmlNotAllowedMessage($methods);
55  break;
56  default:
57  throw new UnexpectedValueException('Cannot render unknown content type ' . $contentType);
58  }
59  }
60 
61  $body = new Body(fopen('php://temp', 'r+'));
62  $body->write($output);
63  $allow = implode(', ', $methods);
64 
65  return $response
66  ->withStatus($status)
67  ->withHeader('Content-type', $contentType)
68  ->withHeader('Allow', $allow)
69  ->withBody($body);
70  }
renderXmlNotAllowedMessage($methods)
Render XML not allowed message.
Definition: NotAllowed.php:104
renderPlainOptionsMessage($methods)
Render PLAIN message for OPTIONS response.
Definition: NotAllowed.php:78
determineContentType(ServerRequestInterface $request)
Determine which content type we know about is wanted using Accept header.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
renderHtmlNotAllowedMessage($methods)
Render HTML not allowed message.
Definition: NotAllowed.php:117
renderJsonNotAllowedMessage($methods)
Render JSON not allowed message.
Definition: NotAllowed.php:91
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
+ Here is the call graph for this function:

◆ renderHtmlNotAllowedMessage()

Slim\Handlers\NotAllowed::renderHtmlNotAllowedMessage (   $methods)
protected

Render HTML not allowed message.

Parameters
array$methods
Returns
string

Definition at line 117 of file NotAllowed.php.

References $output, font, html(), Method, and size.

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

118  {
119  $allow = implode(', ', $methods);
120  $output = <<<END
121 <html>
122  <head>
123  <title>Method not allowed</title>
124  <style>
125  body{
126  margin:0;
127  padding:30px;
128  font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;
129  }
130  h1{
131  margin:0;
132  font-size:48px;
133  font-weight:normal;
134  line-height:48px;
135  }
136  </style>
137  </head>
138  <body>
139  <h1>Method not allowed</h1>
140  <p>Method not allowed. Must be one of: <strong>$allow</strong></p>
141  </body>
142 </html>
143 END;
144 
145  return $output;
146  }
"color:#CC0000 style
Definition: example_001.php:92
Set default font
Definition: 02types-xls.php:55
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
$sc Method
html()
Set page orientation and size
Definition: 04printing.php:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderJsonNotAllowedMessage()

Slim\Handlers\NotAllowed::renderJsonNotAllowedMessage (   $methods)
protected

Render JSON not allowed message.

Parameters
array$methods
Returns
string

Definition at line 91 of file NotAllowed.php.

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

92  {
93  $allow = implode(', ', $methods);
94 
95  return '{"message":"Method not allowed. Must be one of: ' . $allow . '"}';
96  }
+ Here is the caller graph for this function:

◆ renderPlainOptionsMessage()

Slim\Handlers\NotAllowed::renderPlainOptionsMessage (   $methods)
protected

Render PLAIN message for OPTIONS response.

Parameters
array$methods
Returns
string

Definition at line 78 of file NotAllowed.php.

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

79  {
80  $allow = implode(', ', $methods);
81 
82  return 'Allowed methods: ' . $allow;
83  }
+ Here is the caller graph for this function:

◆ renderXmlNotAllowedMessage()

Slim\Handlers\NotAllowed::renderXmlNotAllowedMessage (   $methods)
protected

Render XML not allowed message.

Parameters
array$methods
Returns
string

Definition at line 104 of file NotAllowed.php.

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

105  {
106  $allow = implode(', ', $methods);
107 
108  return "<root><message>Method not allowed. Must be one of: $allow</message></root>";
109  }
+ Here is the caller graph for this function:

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