123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <?php
- namespace Symfony\Component\Routing;
- use Symfony\Component\HttpFoundation\Request;
- class RequestContext
- {
- private $baseUrl;
- private $pathInfo;
- private $method;
- private $host;
- private $scheme;
- private $httpPort;
- private $httpsPort;
- private $queryString;
- private $parameters = [];
- public function __construct(string $baseUrl = '', string $method = 'GET', string $host = 'localhost', string $scheme = 'http', int $httpPort = 80, int $httpsPort = 443, string $path = '/', string $queryString = '')
- {
- $this->setBaseUrl($baseUrl);
- $this->setMethod($method);
- $this->setHost($host);
- $this->setScheme($scheme);
- $this->setHttpPort($httpPort);
- $this->setHttpsPort($httpsPort);
- $this->setPathInfo($path);
- $this->setQueryString($queryString);
- }
-
- public function fromRequest(Request $request)
- {
- $this->setBaseUrl($request->getBaseUrl());
- $this->setPathInfo($request->getPathInfo());
- $this->setMethod($request->getMethod());
- $this->setHost($request->getHost());
- $this->setScheme($request->getScheme());
- $this->setHttpPort($request->isSecure() || null === $request->getPort() ? $this->httpPort : $request->getPort());
- $this->setHttpsPort($request->isSecure() && null !== $request->getPort() ? $request->getPort() : $this->httpsPort);
- $this->setQueryString($request->server->get('QUERY_STRING', ''));
- return $this;
- }
-
- public function getBaseUrl()
- {
- return $this->baseUrl;
- }
-
- public function setBaseUrl(string $baseUrl)
- {
- $this->baseUrl = $baseUrl;
- return $this;
- }
-
- public function getPathInfo()
- {
- return $this->pathInfo;
- }
-
- public function setPathInfo(string $pathInfo)
- {
- $this->pathInfo = $pathInfo;
- return $this;
- }
-
- public function getMethod()
- {
- return $this->method;
- }
-
- public function setMethod(string $method)
- {
- $this->method = strtoupper($method);
- return $this;
- }
-
- public function getHost()
- {
- return $this->host;
- }
-
- public function setHost(string $host)
- {
- $this->host = strtolower($host);
- return $this;
- }
-
- public function getScheme()
- {
- return $this->scheme;
- }
-
- public function setScheme(string $scheme)
- {
- $this->scheme = strtolower($scheme);
- return $this;
- }
-
- public function getHttpPort()
- {
- return $this->httpPort;
- }
-
- public function setHttpPort(int $httpPort)
- {
- $this->httpPort = $httpPort;
- return $this;
- }
-
- public function getHttpsPort()
- {
- return $this->httpsPort;
- }
-
- public function setHttpsPort(int $httpsPort)
- {
- $this->httpsPort = $httpsPort;
- return $this;
- }
-
- public function getQueryString()
- {
- return $this->queryString;
- }
-
- public function setQueryString(?string $queryString)
- {
-
- $this->queryString = (string) $queryString;
- return $this;
- }
-
- public function getParameters()
- {
- return $this->parameters;
- }
-
- public function setParameters(array $parameters)
- {
- $this->parameters = $parameters;
- return $this;
- }
-
- public function getParameter(string $name)
- {
- return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
- }
-
- public function hasParameter(string $name)
- {
- return \array_key_exists($name, $this->parameters);
- }
-
- public function setParameter(string $name, $parameter)
- {
- $this->parameters[$name] = $parameter;
- return $this;
- }
- }
|