1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WebHemi. |
4
|
|
|
* |
5
|
|
|
* PHP version 5.6 |
6
|
|
|
* |
7
|
|
|
* @copyright 2012 - 2016 Gixx-web (http://www.gixx-web.com) |
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
9
|
|
|
* |
10
|
|
|
* @link http://www.gixx-web.com |
11
|
|
|
*/ |
12
|
|
|
namespace WebHemi\Routing; |
13
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class Result. |
18
|
|
|
*/ |
19
|
|
|
class Result |
20
|
|
|
{ |
21
|
|
|
const CODE_FOUND = 200; |
22
|
|
|
const CODE_NOT_FOUND = 404; |
23
|
|
|
const CODE_BAD_METHOD = 405; |
24
|
|
|
|
25
|
|
|
/** @var int */ |
26
|
|
|
private $status; |
27
|
|
|
/** @var string */ |
28
|
|
|
private $matchedMiddleware; |
29
|
|
|
/** @var array */ |
30
|
|
|
private $statusReason = [ |
31
|
|
|
self::CODE_FOUND => 'Resource found.', |
32
|
|
|
self::CODE_NOT_FOUND => 'The requested resource cannot be found.', |
33
|
|
|
self::CODE_BAD_METHOD => 'Bad request method was used by the client.' |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Sets status code. |
38
|
|
|
* |
39
|
|
|
* @param int $status |
40
|
|
|
* |
41
|
|
|
* @throws InvalidArgumentException |
42
|
|
|
* |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
2 |
|
public function setStatus($status) |
46
|
|
|
{ |
47
|
2 |
|
if (!isset($this->statusReason[$status])) { |
48
|
1 |
|
throw new InvalidArgumentException(sprintf('The parameter "%s" is not a valid routing status.', $status)); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
$this->status = $status; |
52
|
|
|
|
53
|
1 |
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Gets status code. |
58
|
|
|
* |
59
|
|
|
* @return int |
60
|
|
|
*/ |
61
|
1 |
|
public function getStatus() |
62
|
|
|
{ |
63
|
1 |
|
return $this->status; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Gets reason for the status set. |
68
|
|
|
* |
69
|
|
|
* @return false|string |
70
|
|
|
*/ |
71
|
1 |
|
public function getStatusReason() |
72
|
|
|
{ |
73
|
1 |
|
return isset($this->statusReason[$this->status]) ? $this->statusReason[$this->status] : false; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Sets matched middleware. |
78
|
|
|
* |
79
|
|
|
* @param string $matchedMiddleware |
80
|
|
|
*/ |
81
|
1 |
|
public function setMatchedMiddleware($matchedMiddleware) |
82
|
|
|
{ |
83
|
1 |
|
$this->matchedMiddleware = $matchedMiddleware; |
84
|
1 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Gets matched middleware. |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
1 |
|
public function getMatchedMiddleware() |
92
|
|
|
{ |
93
|
1 |
|
return $this->matchedMiddleware; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|