1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
4
|
|
|
* |
5
|
|
|
* @package MyArtJaub\Webtrees |
6
|
|
|
* @subpackage Mvc |
7
|
|
|
* @author Jonathan Jaubart <[email protected]> |
8
|
|
|
* @copyright Copyright (c) 2016, Jonathan Jaubart |
9
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
10
|
|
|
*/ |
11
|
|
|
namespace MyArtJaub\Webtrees\Mvc; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Specific Exception for MyArtJaub Exception |
15
|
|
|
* @see \Exception |
16
|
|
|
*/ |
17
|
|
|
class MvcException extends \Exception { |
18
|
|
|
|
19
|
|
|
/** @var int[] $VALID_HTTP List of valid HTTP codes */ |
20
|
|
|
protected static $VALID_HTTP = array( |
21
|
|
|
100, 101, |
22
|
|
|
200, 201, 202, 203, 204, 205, 206, |
23
|
|
|
300, 301, 302, 303, 304, 305, 306, 307, |
24
|
|
|
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, |
25
|
|
|
500, 501, 502, 503, 504, 505 |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
/** @var int $http_code */ |
29
|
|
|
protected $http_code; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constructor for MvcException |
33
|
|
|
* |
34
|
|
|
* @param int $http_code |
35
|
|
|
* @param string $message |
36
|
|
|
* @param int $code |
37
|
|
|
* @param \Throwable $previous |
38
|
|
|
*/ |
39
|
|
|
public function __construct($http_code = 500, $message = "", $code = 0, \Throwable $previous = null) { |
40
|
|
|
parent::__construct($message, $code, $previous); |
41
|
|
|
|
42
|
|
|
$this->http_code = in_array($http_code, self::$VALID_HTTP) ? $http_code : 500; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the HTTP code |
47
|
|
|
* |
48
|
|
|
* @return int |
49
|
|
|
*/ |
50
|
|
|
public function getHttpCode() { |
51
|
|
|
return $this->http_code; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Set the HTTP code |
56
|
|
|
* |
57
|
|
|
* @param int $http_code |
58
|
|
|
* @throws InvalidArgumentException Thrown if not valid Http code |
59
|
|
|
*/ |
60
|
|
|
public function setHttpCode($http_code) { |
61
|
|
|
if(!in_array($http_code, self::$VALID_HTTP)) |
62
|
|
|
throw new \InvalidArgumentException('Invalid HTTP code'); |
63
|
|
|
$this->http_code= $http_code; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|