|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony package. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\Routing; |
|
|
13 |
|
|
|
14 |
/** |
|
|
15 |
* Holds information about the current request. |
|
|
16 |
* |
|
|
17 |
* @author Fabien Potencier <fabien@symfony.com> |
|
|
18 |
* |
|
|
19 |
* @api |
|
|
20 |
*/ |
|
|
21 |
class RequestContext |
|
|
22 |
{ |
|
|
23 |
private $baseUrl; |
|
|
24 |
private $method; |
|
|
25 |
private $host; |
|
|
26 |
private $scheme; |
|
|
27 |
private $httpPort; |
|
|
28 |
private $httpsPort; |
|
|
29 |
private $parameters; |
|
|
30 |
|
|
|
31 |
/** |
|
|
32 |
* Constructor. |
|
|
33 |
* |
|
|
34 |
* @param string $baseUrl The base URL |
|
|
35 |
* @param string $method The HTTP method |
|
|
36 |
* @param string $host The HTTP host name |
|
|
37 |
* @param string $scheme The HTTP scheme |
|
|
38 |
* @param integer $httpPort The HTTP port |
|
|
39 |
* @param integer $httpsPort The HTTPS port |
|
|
40 |
* |
|
|
41 |
* @api |
|
|
42 |
*/ |
|
|
43 |
public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443) |
|
|
44 |
{ |
|
|
45 |
$this->baseUrl = $baseUrl; |
|
|
46 |
$this->method = strtoupper($method); |
|
|
47 |
$this->host = $host; |
|
|
48 |
$this->scheme = strtolower($scheme); |
|
|
49 |
$this->httpPort = $httpPort; |
|
|
50 |
$this->httpsPort = $httpsPort; |
|
|
51 |
$this->parameters = array(); |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
/** |
|
|
55 |
* Gets the base URL. |
|
|
56 |
* |
|
|
57 |
* @return string The base URL |
|
|
58 |
*/ |
|
|
59 |
public function getBaseUrl() |
|
|
60 |
{ |
|
|
61 |
return $this->baseUrl; |
|
|
62 |
} |
|
|
63 |
|
|
|
64 |
/** |
|
|
65 |
* Sets the base URL. |
|
|
66 |
* |
|
|
67 |
* @param string $baseUrl The base URL |
|
|
68 |
* |
|
|
69 |
* @api |
|
|
70 |
*/ |
|
|
71 |
public function setBaseUrl($baseUrl) |
|
|
72 |
{ |
|
|
73 |
$this->baseUrl = $baseUrl; |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
/** |
|
|
77 |
* Gets the HTTP method. |
|
|
78 |
* |
|
|
79 |
* The method is always an uppercased string. |
|
|
80 |
* |
|
|
81 |
* @return string The HTTP method |
|
|
82 |
*/ |
|
|
83 |
public function getMethod() |
|
|
84 |
{ |
|
|
85 |
return $this->method; |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
/** |
|
|
89 |
* Sets the HTTP method. |
|
|
90 |
* |
|
|
91 |
* @param string $method The HTTP method |
|
|
92 |
* |
|
|
93 |
* @api |
|
|
94 |
*/ |
|
|
95 |
public function setMethod($method) |
|
|
96 |
{ |
|
|
97 |
$this->method = strtoupper($method); |
|
|
98 |
} |
|
|
99 |
|
|
|
100 |
/** |
|
|
101 |
* Gets the HTTP host. |
|
|
102 |
* |
|
|
103 |
* @return string The HTTP host |
|
|
104 |
*/ |
|
|
105 |
public function getHost() |
|
|
106 |
{ |
|
|
107 |
return $this->host; |
|
|
108 |
} |
|
|
109 |
|
|
|
110 |
/** |
|
|
111 |
* Sets the HTTP host. |
|
|
112 |
* |
|
|
113 |
* @param string $host The HTTP host |
|
|
114 |
* |
|
|
115 |
* @api |
|
|
116 |
*/ |
|
|
117 |
public function setHost($host) |
|
|
118 |
{ |
|
|
119 |
$this->host = $host; |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
/** |
|
|
123 |
* Gets the HTTP scheme. |
|
|
124 |
* |
|
|
125 |
* @return string The HTTP scheme |
|
|
126 |
*/ |
|
|
127 |
public function getScheme() |
|
|
128 |
{ |
|
|
129 |
return $this->scheme; |
|
|
130 |
} |
|
|
131 |
|
|
|
132 |
/** |
|
|
133 |
* Sets the HTTP scheme. |
|
|
134 |
* |
|
|
135 |
* @param string $scheme The HTTP scheme |
|
|
136 |
* |
|
|
137 |
* @api |
|
|
138 |
*/ |
|
|
139 |
public function setScheme($scheme) |
|
|
140 |
{ |
|
|
141 |
$this->scheme = strtolower($scheme); |
|
|
142 |
} |
|
|
143 |
|
|
|
144 |
/** |
|
|
145 |
* Gets the HTTP port. |
|
|
146 |
* |
|
|
147 |
* @return string The HTTP port |
|
|
148 |
*/ |
|
|
149 |
public function getHttpPort() |
|
|
150 |
{ |
|
|
151 |
return $this->httpPort; |
|
|
152 |
} |
|
|
153 |
|
|
|
154 |
/** |
|
|
155 |
* Sets the HTTP port. |
|
|
156 |
* |
|
|
157 |
* @param string $httpPort The HTTP port |
|
|
158 |
* |
|
|
159 |
* @api |
|
|
160 |
*/ |
|
|
161 |
public function setHttpPort($httpPort) |
|
|
162 |
{ |
|
|
163 |
$this->httpPort = $httpPort; |
|
|
164 |
} |
|
|
165 |
|
|
|
166 |
/** |
|
|
167 |
* Gets the HTTPS port. |
|
|
168 |
* |
|
|
169 |
* @return string The HTTPS port |
|
|
170 |
*/ |
|
|
171 |
public function getHttpsPort() |
|
|
172 |
{ |
|
|
173 |
return $this->httpsPort; |
|
|
174 |
} |
|
|
175 |
|
|
|
176 |
/** |
|
|
177 |
* Sets the HTTPS port. |
|
|
178 |
* |
|
|
179 |
* @param string $httpsPort The HTTPS port |
|
|
180 |
* |
|
|
181 |
* @api |
|
|
182 |
*/ |
|
|
183 |
public function setHttpsPort($httpsPort) |
|
|
184 |
{ |
|
|
185 |
$this->httpsPort = $httpsPort; |
|
|
186 |
} |
|
|
187 |
|
|
|
188 |
/** |
|
|
189 |
* Returns the parameters. |
|
|
190 |
* |
|
|
191 |
* @return array The parameters |
|
|
192 |
*/ |
|
|
193 |
public function getParameters() |
|
|
194 |
{ |
|
|
195 |
return $this->parameters; |
|
|
196 |
} |
|
|
197 |
|
|
|
198 |
/** |
|
|
199 |
* Sets the parameters. |
|
|
200 |
* |
|
|
201 |
* This method implements a fluent interface. |
|
|
202 |
* |
|
|
203 |
* @param array $parameters The parameters |
|
|
204 |
* |
|
|
205 |
* @return Route The current Route instance |
|
|
206 |
*/ |
|
|
207 |
public function setParameters(array $parameters) |
|
|
208 |
{ |
|
|
209 |
$this->parameters = $parameters; |
|
|
210 |
|
|
|
211 |
return $this; |
|
|
212 |
} |
|
|
213 |
|
|
|
214 |
/** |
|
|
215 |
* Gets a parameter value. |
|
|
216 |
* |
|
|
217 |
* @param string $name A parameter name |
|
|
218 |
* |
|
|
219 |
* @return mixed The parameter value |
|
|
220 |
*/ |
|
|
221 |
public function getParameter($name) |
|
|
222 |
{ |
|
|
223 |
return isset($this->parameters[$name]) ? $this->parameters[$name] : null; |
|
|
224 |
} |
|
|
225 |
|
|
|
226 |
/** |
|
|
227 |
* Checks if a parameter value is set for the given parameter. |
|
|
228 |
* |
|
|
229 |
* @param string $name A parameter name |
|
|
230 |
* |
|
|
231 |
* @return Boolean true if the parameter value is set, false otherwise |
|
|
232 |
*/ |
|
|
233 |
public function hasParameter($name) |
|
|
234 |
{ |
|
|
235 |
return array_key_exists($name, $this->parameters); |
|
|
236 |
} |
|
|
237 |
|
|
|
238 |
/** |
|
|
239 |
* Sets a parameter value. |
|
|
240 |
* |
|
|
241 |
* @param string $name A parameter name |
|
|
242 |
* @param mixed $parameter The parameter value |
|
|
243 |
* |
|
|
244 |
* @api |
|
|
245 |
*/ |
|
|
246 |
public function setParameter($name, $parameter) |
|
|
247 |
{ |
|
|
248 |
$this->parameters[$name] = $parameter; |
|
|
249 |
} |
|
|
250 |
} |