1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Anax\MVC; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Anax base class implementing Dependency Injection / Service Locator |
7
|
|
|
* of the services used by the framework, using lazy loading. |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
class ErrorController |
11
|
|
|
{ |
12
|
|
|
use \Anax\DI\TInjectionAware; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Display a page for a HTTP status code. |
18
|
|
|
* |
19
|
|
|
* @param string code status code to set the http header. |
20
|
|
|
* @param string message an optional message to display together with the error code. |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function statusCodeAction($code = null, $message = null) |
25
|
|
|
{ |
26
|
|
|
$codes = [ |
27
|
|
|
403 => "403 Forbidden", |
28
|
|
|
404 => "404 Not Found", |
29
|
|
|
500 => "500 Internal Server Error", |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
// Key being integer also (unintentionally) prevents this action from direct url usage |
33
|
|
|
if (!$code || !in_array($code, $codes)) { |
34
|
|
|
throw new \Anax\Exception\NotFoundException("Not a valid HTTP status code."); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$title = $codes[$code]; |
38
|
|
|
$this->di->response->setHeader($code); |
39
|
|
|
$this->di->theme->setTitle($title); |
40
|
|
|
$this->di->views->add('default/error', [ |
41
|
|
|
'title' => $title, |
42
|
|
|
'content' => $message, |
43
|
|
|
'details' => $this->di->flash->getMessage(), |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Display a list of valid routes. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function displayValidRoutesAction() |
55
|
|
|
{ |
56
|
|
|
$this->di->views->add('default/error-routes', [ |
57
|
|
|
'route' => $this->di->request->getRoute(), |
58
|
|
|
'routes' => $this->di->router->getAll(), |
59
|
|
|
'internalRoutes' => $this->di->router->getInternal(), |
60
|
|
|
'controllers' => $this->di->getControllers(), |
61
|
|
|
]); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|