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
|
|
|
/** @var array */ |
36
|
|
|
private $parameters; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Sets status code. |
40
|
|
|
* |
41
|
|
|
* @param int $status |
42
|
|
|
* |
43
|
|
|
* @throws InvalidArgumentException |
44
|
|
|
* |
45
|
|
|
* @return $this |
46
|
|
|
*/ |
47
|
6 |
|
public function setStatus($status) |
48
|
|
|
{ |
49
|
6 |
|
if (!isset($this->statusReason[$status])) { |
50
|
1 |
|
throw new InvalidArgumentException(sprintf('The parameter "%s" is not a valid routing status.', $status)); |
51
|
|
|
} |
52
|
|
|
|
53
|
5 |
|
$this->status = $status; |
54
|
|
|
|
55
|
5 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Gets status code. |
60
|
|
|
* |
61
|
|
|
* @return int |
62
|
|
|
*/ |
63
|
5 |
|
public function getStatus() |
64
|
|
|
{ |
65
|
5 |
|
return $this->status; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Gets reason for the status set. |
70
|
|
|
* |
71
|
|
|
* @return false|string |
72
|
|
|
*/ |
73
|
1 |
|
public function getStatusReason() |
74
|
|
|
{ |
75
|
1 |
|
return isset($this->statusReason[$this->status]) ? $this->statusReason[$this->status] : false; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Sets matched middleware. |
80
|
|
|
* |
81
|
|
|
* @param string $matchedMiddleware |
82
|
|
|
* |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
5 |
|
public function setMatchedMiddleware($matchedMiddleware) |
86
|
|
|
{ |
87
|
5 |
|
$this->matchedMiddleware = $matchedMiddleware; |
88
|
|
|
|
89
|
5 |
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Gets matched middleware. |
94
|
|
|
* |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
5 |
|
public function getMatchedMiddleware() |
98
|
|
|
{ |
99
|
5 |
|
return $this->matchedMiddleware; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Sets the parameters. |
104
|
|
|
* |
105
|
|
|
* @param array $parameters |
106
|
|
|
* |
107
|
|
|
* @return $this |
108
|
|
|
*/ |
109
|
5 |
|
public function setParameters(array $parameters) |
110
|
|
|
{ |
111
|
5 |
|
$this->parameters = $parameters; |
112
|
|
|
|
113
|
5 |
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Gets the parameters. |
118
|
|
|
* |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
3 |
|
public function getParameters() |
122
|
|
|
{ |
123
|
3 |
|
return $this->parameters; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|