PageRenderTime 54ms CodeModel.GetById 32ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/module/Core/controller/Error.php

https://github.com/tquensen/QPMS
PHP | 94 lines | 81 code | 13 blank | 0 comment | 30 complexity | 0a5425f358592ffab7ae371d7fbd12cb MD5 | raw file
 1<?php 
 2class Core_Error_Controller extends MiniMVC_Controller
 3{
 4    protected $serverErrorCodes = array(
 5        500 => '500 Internal Server Error',
 6        501 => '501 Not Implemented',
 7        502 => '502 Bad Gateway',
 8        503 => '503 Service Unavailable',
 9        504 => '504 Gateway Time-out',
10        505 => '505 HTTP Version not supported',
11        506 => '506 Variant Also Negotiates',
12        507 => '507 Insufficient Storage',
13        509 => '509 Bandwidth Limit Exceeded',
14        510 => '510 Not Extended',
15    );
16
17	public function error401Action($params)
18	{
19        $this->registry->helper->meta->setTitle('Error 401 Unauthorized', false);
20        $this->registry->helper->meta->setDescription('');
21        header('HTTP/1.1 401 Unauthorized', true, 401);
22
23        if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
24            $this->view->message = $params['exception']->getMessage();
25        } else {
26            $this->view->message = 'Error 401 Unauthorized';
27        }
28
29        if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
30            $this->view->e = $params['exception'];
31            $this->view->setFile('error/error401debug');
32        }
33	}
34	
35	public function error403Action($params)
36	{
37        $this->registry->helper->meta->setTitle('Error 403 Forbidden', false);
38        $this->registry->helper->meta->setDescription('');
39		header('HTTP/1.1 403 Forbidden', true, 403);
40
41        if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
42            $this->view->message = $params['exception']->getMessage();
43        } else {
44            $this->view->message = 'Error 403 Forbidden';
45        }
46
47        if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
48            $this->view->e = $params['exception'];
49            $this->view->setFile('error/error403debug');
50        }
51	}
52	
53	public function error404Action($params)
54	{
55        $this->registry->helper->meta->setTitle('Error 404 Not Found', false);
56        $this->registry->helper->meta->setDescription('');
57		header('HTTP/1.1 404 Not Found', true, 404);
58
59        if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
60            $this->view->message = $params['exception']->getMessage();
61        } else {
62            $this->view->message = 'Error 404 Not Found';
63        }
64
65        if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
66            $this->view->e = $params['exception'];
67            $this->view->setFile('error/error404debug');
68        }
69	}
70
71    public function error500Action($params)
72	{
73        if (isset($params['exception']) && isset($this->serverErrorCodes[$params['exception']->getCode()])) {
74            $this->registry->helper->meta->setTitle('Error '.$this->serverErrorCodes[$params['exception']->getCode()], false);
75            $this->view->message = 'Error '.$this->serverErrorCodes[$params['exception']->getCode()];
76            header($this->serverErrorCodes[$params['exception']->getCode()], true, $params['exception']->getCode());
77        } else {
78            $this->registry->helper->meta->setTitle('Error 500 Internal Server Error', false);
79            $this->view->message = 'Error 500 Internal Server Error';
80            header('500 Internal Server Error', true, 500);
81        }
82
83        $this->registry->helper->meta->setDescription('');
84        
85        if (isset($params['exception']) && $params['exception'] instanceof MiniMVC_PublicHttpException && $params['exception']->getMessage()) {
86            $this->view->message = $params['exception']->getMessage();
87        }
88
89        if (isset($params['debug']) && $params['debug'] && isset($params['exception'])) {
90            $this->view->e = $params['exception'];
91            $this->view->setFile('error/error500debug');
92        }
93	}
94}