]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/routing/Symfony/Component/Routing/RequestContext.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / routing / Symfony / Component / Routing / RequestContext.php
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 use Symfony\Component\HttpFoundation\Request;
15
16 /**
17 * Holds information about the current request.
18 *
19 * @author Fabien Potencier <fabien@symfony.com>
20 *
21 * @api
22 */
23 class RequestContext
24 {
25 private $baseUrl;
26 private $pathInfo;
27 private $method;
28 private $host;
29 private $scheme;
30 private $httpPort;
31 private $httpsPort;
32 private $queryString;
33
34 /**
35 * @var array
36 */
37 private $parameters = array();
38
39 /**
40 * Constructor.
41 *
42 * @param string $baseUrl The base URL
43 * @param string $method The HTTP method
44 * @param string $host The HTTP host name
45 * @param string $scheme The HTTP scheme
46 * @param integer $httpPort The HTTP port
47 * @param integer $httpsPort The HTTPS port
48 * @param string $path The path
49 * @param string $queryString The query string
50 *
51 * @api
52 */
53 public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443, $path = '/', $queryString = '')
54 {
55 $this->baseUrl = $baseUrl;
56 $this->method = strtoupper($method);
57 $this->host = $host;
58 $this->scheme = strtolower($scheme);
59 $this->httpPort = $httpPort;
60 $this->httpsPort = $httpsPort;
61 $this->pathInfo = $path;
62 $this->queryString = $queryString;
63 }
64
65 public function fromRequest(Request $request)
66 {
67 $this->setBaseUrl($request->getBaseUrl());
68 $this->setPathInfo($request->getPathInfo());
69 $this->setMethod($request->getMethod());
70 $this->setHost($request->getHost());
71 $this->setScheme($request->getScheme());
72 $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
73 $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
74 $this->setQueryString($request->server->get('QUERY_STRING'));
75 }
76
77 /**
78 * Gets the base URL.
79 *
80 * @return string The base URL
81 */
82 public function getBaseUrl()
83 {
84 return $this->baseUrl;
85 }
86
87 /**
88 * Sets the base URL.
89 *
90 * @param string $baseUrl The base URL
91 *
92 * @api
93 */
94 public function setBaseUrl($baseUrl)
95 {
96 $this->baseUrl = $baseUrl;
97 }
98
99 /**
100 * Gets the path info.
101 *
102 * @return string The path info
103 */
104 public function getPathInfo()
105 {
106 return $this->pathInfo;
107 }
108
109 /**
110 * Sets the path info.
111 *
112 * @param string $pathInfo The path info
113 */
114 public function setPathInfo($pathInfo)
115 {
116 $this->pathInfo = $pathInfo;
117 }
118
119 /**
120 * Gets the HTTP method.
121 *
122 * The method is always an uppercased string.
123 *
124 * @return string The HTTP method
125 */
126 public function getMethod()
127 {
128 return $this->method;
129 }
130
131 /**
132 * Sets the HTTP method.
133 *
134 * @param string $method The HTTP method
135 *
136 * @api
137 */
138 public function setMethod($method)
139 {
140 $this->method = strtoupper($method);
141 }
142
143 /**
144 * Gets the HTTP host.
145 *
146 * @return string The HTTP host
147 */
148 public function getHost()
149 {
150 return $this->host;
151 }
152
153 /**
154 * Sets the HTTP host.
155 *
156 * @param string $host The HTTP host
157 *
158 * @api
159 */
160 public function setHost($host)
161 {
162 $this->host = $host;
163 }
164
165 /**
166 * Gets the HTTP scheme.
167 *
168 * @return string The HTTP scheme
169 */
170 public function getScheme()
171 {
172 return $this->scheme;
173 }
174
175 /**
176 * Sets the HTTP scheme.
177 *
178 * @param string $scheme The HTTP scheme
179 *
180 * @api
181 */
182 public function setScheme($scheme)
183 {
184 $this->scheme = strtolower($scheme);
185 }
186
187 /**
188 * Gets the HTTP port.
189 *
190 * @return string The HTTP port
191 */
192 public function getHttpPort()
193 {
194 return $this->httpPort;
195 }
196
197 /**
198 * Sets the HTTP port.
199 *
200 * @param string $httpPort The HTTP port
201 *
202 * @api
203 */
204 public function setHttpPort($httpPort)
205 {
206 $this->httpPort = $httpPort;
207 }
208
209 /**
210 * Gets the HTTPS port.
211 *
212 * @return string The HTTPS port
213 */
214 public function getHttpsPort()
215 {
216 return $this->httpsPort;
217 }
218
219 /**
220 * Sets the HTTPS port.
221 *
222 * @param string $httpsPort The HTTPS port
223 *
224 * @api
225 */
226 public function setHttpsPort($httpsPort)
227 {
228 $this->httpsPort = $httpsPort;
229 }
230
231 /**
232 * Gets the query string.
233 *
234 * @return string The query string
235 */
236 public function getQueryString()
237 {
238 return $this->queryString;
239 }
240
241 /**
242 * Sets the query string.
243 *
244 * @param string $queryString The query string
245 *
246 * @api
247 */
248 public function setQueryString($queryString)
249 {
250 $this->queryString = $queryString;
251 }
252
253 /**
254 * Returns the parameters.
255 *
256 * @return array The parameters
257 */
258 public function getParameters()
259 {
260 return $this->parameters;
261 }
262
263 /**
264 * Sets the parameters.
265 *
266 * This method implements a fluent interface.
267 *
268 * @param array $parameters The parameters
269 *
270 * @return Route The current Route instance
271 */
272 public function setParameters(array $parameters)
273 {
274 $this->parameters = $parameters;
275
276 return $this;
277 }
278
279 /**
280 * Gets a parameter value.
281 *
282 * @param string $name A parameter name
283 *
284 * @return mixed The parameter value
285 */
286 public function getParameter($name)
287 {
288 return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
289 }
290
291 /**
292 * Checks if a parameter value is set for the given parameter.
293 *
294 * @param string $name A parameter name
295 *
296 * @return Boolean true if the parameter value is set, false otherwise
297 */
298 public function hasParameter($name)
299 {
300 return array_key_exists($name, $this->parameters);
301 }
302
303 /**
304 * Sets a parameter value.
305 *
306 * @param string $name A parameter name
307 * @param mixed $parameter The parameter value
308 *
309 * @api
310 */
311 public function setParameter($name, $parameter)
312 {
313 $this->parameters[$name] = $parameter;
314 }
315 }