| @@ 6-51 (lines=46) @@ | ||
| 3 | ||
| 4 | use Slim\Interfaces\RenderableInterface; |
|
| 5 | ||
| 6 | class HtmlNotAllowedMessage implements RenderableInterface |
|
| 7 | { |
|
| 8 | ||
| 9 | public function render($args) |
|
| 10 | { |
|
| 11 | return $this->renderHtmlNotAllowedMessage($args[0]); |
|
| 12 | } |
|
| 13 | ||
| 14 | ||
| 15 | /** |
|
| 16 | * Render HTML not allowed message |
|
| 17 | * |
|
| 18 | * @param array $methods |
|
| 19 | * @return string |
|
| 20 | */ |
|
| 21 | protected function renderHtmlNotAllowedMessage($methods) |
|
| 22 | { |
|
| 23 | $allow = implode(', ', $methods); |
|
| 24 | $output = <<<END |
|
| 25 | <html> |
|
| 26 | <head> |
|
| 27 | <title>Method not allowed</title> |
|
| 28 | <style> |
|
| 29 | body{ |
|
| 30 | margin:0; |
|
| 31 | padding:30px; |
|
| 32 | font:12px/1.5 Helvetica,Arial,Verdana,sans-serif; |
|
| 33 | } |
|
| 34 | h1{ |
|
| 35 | margin:0; |
|
| 36 | font-size:48px; |
|
| 37 | font-weight:normal; |
|
| 38 | line-height:48px; |
|
| 39 | } |
|
| 40 | </style> |
|
| 41 | </head> |
|
| 42 | <body> |
|
| 43 | <h1>Method not allowed</h1> |
|
| 44 | <p>Method not allowed. Must be one of: <strong>$allow</strong></p> |
|
| 45 | </body> |
|
| 46 | </html> |
|
| 47 | END; |
|
| 48 | ||
| 49 | return $output; |
|
| 50 | } |
|
| 51 | } |
|
| @@ 6-31 (lines=26) @@ | ||
| 3 | ||
| 4 | use Slim\Interfaces\RenderableInterface; |
|
| 5 | ||
| 6 | class JsonNotAllowedMessage implements RenderableInterface |
|
| 7 | { |
|
| 8 | ||
| 9 | ||
| 10 | public function render($args) |
|
| 11 | { |
|
| 12 | $methods = $args[0]; |
|
| 13 | return $this->renderJsonNotAllowedMessage($methods); |
|
| 14 | } |
|
| 15 | ||
| 16 | ||
| 17 | /** |
|
| 18 | * Render JSON not allowed message |
|
| 19 | * |
|
| 20 | * @param array $methods |
|
| 21 | * @return string |
|
| 22 | */ |
|
| 23 | protected function renderJsonNotAllowedMessage($methods) |
|
| 24 | { |
|
| 25 | $allow = implode(', ', $methods); |
|
| 26 | ||
| 27 | return '{"message":"Method not allowed. Must be one of: ' . $allow . '"}'; |
|
| 28 | } |
|
| 29 | ||
| 30 | ||
| 31 | } |
|
| @@ 6-31 (lines=26) @@ | ||
| 3 | ||
| 4 | use Slim\Interfaces\RenderableInterface; |
|
| 5 | ||
| 6 | class XmlNotAllowedMessage implements RenderableInterface |
|
| 7 | { |
|
| 8 | ||
| 9 | ||
| 10 | public function render($args) |
|
| 11 | { |
|
| 12 | $methods = $args[0]; |
|
| 13 | return $this->renderXmlNotAllowedMessage($methods); |
|
| 14 | } |
|
| 15 | ||
| 16 | ||
| 17 | /** |
|
| 18 | * Render XML not allowed message |
|
| 19 | * |
|
| 20 | * @param array $methods |
|
| 21 | * @return string |
|
| 22 | */ |
|
| 23 | protected function renderXmlNotAllowedMessage($methods) |
|
| 24 | { |
|
| 25 | $allow = implode(', ', $methods); |
|
| 26 | ||
| 27 | return "<root><message>Method not allowed. Must be one of: $allow</message></root>"; |
|
| 28 | } |
|
| 29 | ||
| 30 | ||
| 31 | } |
|