1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the RS Framework. |
4
|
|
|
* |
5
|
|
|
* (c) Dan Smith <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace Ds\Router; |
11
|
|
|
|
12
|
|
|
use Ds\Router\Interfaces\RouterResponseInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* RouterResponse Class. |
16
|
|
|
* |
17
|
|
|
* Contains information about matched Route. |
18
|
|
|
* |
19
|
|
|
* @package Ds\Router |
20
|
|
|
* @author Dan Smith <[email protected]> |
21
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
22
|
|
|
* @link https://red-sqr.co.uk/Framework/Routercin/wikis/ |
23
|
|
|
*/ |
24
|
|
|
class RouterResponse implements RouterResponseInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var int Response Status Code. |
28
|
|
|
*/ |
29
|
|
|
protected $statusCode; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string|\Closure Route Handler. |
33
|
|
|
*/ |
34
|
|
|
protected $handler; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var array Route Query Params. |
38
|
|
|
*/ |
39
|
|
|
protected $vars = []; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array Route Names |
43
|
|
|
*/ |
44
|
|
|
protected $names = []; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Router Response constructor. |
48
|
|
|
* |
49
|
|
|
* @param int $statusCode |
50
|
|
|
* @param string|\Closure $handler |
51
|
|
|
* @param array $names |
52
|
|
|
* @param array $vars |
53
|
|
|
*/ |
54
|
4 |
|
public function __construct( |
55
|
|
|
$statusCode, |
56
|
|
|
$handler, |
57
|
|
|
array $names = [], |
58
|
|
|
array $vars = [] |
59
|
|
|
) |
60
|
|
|
{ |
61
|
4 |
|
$this->statusCode = $statusCode; |
62
|
4 |
|
$this->handler = $handler; |
63
|
4 |
|
$this->names = $names; |
64
|
4 |
|
$this->vars = $vars; |
65
|
4 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritdoc |
69
|
|
|
*/ |
70
|
1 |
|
public function getHandler() |
71
|
|
|
{ |
72
|
1 |
|
return $this->handler; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritdoc |
77
|
|
|
*/ |
78
|
1 |
|
public function getStatusCode() |
79
|
|
|
{ |
80
|
1 |
|
return $this->statusCode; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
*/ |
86
|
1 |
|
public function getVars() |
87
|
|
|
{ |
88
|
1 |
|
return $this->vars; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
*/ |
94
|
1 |
|
public function getNames() |
95
|
|
|
{ |
96
|
1 |
|
return $this->names; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $handler |
101
|
|
|
* @return RouterResponse |
102
|
|
|
*/ |
103
|
|
|
public function withHandler(string $handler){ |
104
|
|
|
$new = clone $this; |
105
|
|
|
$new->handler = $handler; |
106
|
|
|
return $new; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param array $vars |
111
|
|
|
* @return RouterResponse |
112
|
|
|
*/ |
113
|
|
|
public function withVars(array $vars){ |
114
|
|
|
$new = clone $this; |
115
|
|
|
$new->vars = $vars; |
116
|
|
|
return $new; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param int $code |
121
|
|
|
* @return RouterResponse |
122
|
|
|
*/ |
123
|
|
|
public function withStatusCode(int $code){ |
124
|
|
|
$new = clone $this; |
125
|
|
|
$new->statusCode = $code; |
126
|
|
|
return $new; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param array $names |
131
|
|
|
* @return RouterResponse |
132
|
|
|
*/ |
133
|
|
|
public function withNames(array $names){ |
134
|
|
|
$new = clone $this; |
135
|
|
|
$new->names = $names; |
136
|
|
|
return $new; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|