4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing
;
14 use Symfony\Component\HttpFoundation\Request
;
17 * Holds information about the current request.
19 * @author Fabien Potencier <fabien@symfony.com>
37 private $parameters = array();
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
53 public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443, $path = '/', $queryString = '')
55 $this->baseUrl
= $baseUrl;
56 $this->method
= strtoupper($method);
58 $this->scheme
= strtolower($scheme);
59 $this->httpPort
= $httpPort;
60 $this->httpsPort
= $httpsPort;
61 $this->pathInfo
= $path;
62 $this->queryString
= $queryString;
65 public function fromRequest(Request
$request)
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'));
80 * @return string The base URL
82 public function getBaseUrl()
84 return $this->baseUrl
;
90 * @param string $baseUrl The base URL
94 public function setBaseUrl($baseUrl)
96 $this->baseUrl
= $baseUrl;
100 * Gets the path info.
102 * @return string The path info
104 public function getPathInfo()
106 return $this->pathInfo
;
110 * Sets the path info.
112 * @param string $pathInfo The path info
114 public function setPathInfo($pathInfo)
116 $this->pathInfo
= $pathInfo;
120 * Gets the HTTP method.
122 * The method is always an uppercased string.
124 * @return string The HTTP method
126 public function getMethod()
128 return $this->method
;
132 * Sets the HTTP method.
134 * @param string $method The HTTP method
138 public function setMethod($method)
140 $this->method
= strtoupper($method);
144 * Gets the HTTP host.
146 * @return string The HTTP host
148 public function getHost()
154 * Sets the HTTP host.
156 * @param string $host The HTTP host
160 public function setHost($host)
166 * Gets the HTTP scheme.
168 * @return string The HTTP scheme
170 public function getScheme()
172 return $this->scheme
;
176 * Sets the HTTP scheme.
178 * @param string $scheme The HTTP scheme
182 public function setScheme($scheme)
184 $this->scheme
= strtolower($scheme);
188 * Gets the HTTP port.
190 * @return string The HTTP port
192 public function getHttpPort()
194 return $this->httpPort
;
198 * Sets the HTTP port.
200 * @param string $httpPort The HTTP port
204 public function setHttpPort($httpPort)
206 $this->httpPort
= $httpPort;
210 * Gets the HTTPS port.
212 * @return string The HTTPS port
214 public function getHttpsPort()
216 return $this->httpsPort
;
220 * Sets the HTTPS port.
222 * @param string $httpsPort The HTTPS port
226 public function setHttpsPort($httpsPort)
228 $this->httpsPort
= $httpsPort;
232 * Gets the query string.
234 * @return string The query string
236 public function getQueryString()
238 return $this->queryString
;
242 * Sets the query string.
244 * @param string $queryString The query string
248 public function setQueryString($queryString)
250 $this->queryString
= $queryString;
254 * Returns the parameters.
256 * @return array The parameters
258 public function getParameters()
260 return $this->parameters
;
264 * Sets the parameters.
266 * This method implements a fluent interface.
268 * @param array $parameters The parameters
270 * @return Route The current Route instance
272 public function setParameters(array $parameters)
274 $this->parameters
= $parameters;
280 * Gets a parameter value.
282 * @param string $name A parameter name
284 * @return mixed The parameter value
286 public function getParameter($name)
288 return isset($this->parameters
[$name]) ? $this->parameters
[$name] : null;
292 * Checks if a parameter value is set for the given parameter.
294 * @param string $name A parameter name
296 * @return Boolean true if the parameter value is set, false otherwise
298 public function hasParameter($name)
300 return array_key_exists($name, $this->parameters
);
304 * Sets a parameter value.
306 * @param string $name A parameter name
307 * @param mixed $parameter The parameter value
311 public function setParameter($name, $parameter)
313 $this->parameters
[$name] = $parameter;