[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/routing/Symfony/Component/Routing/ -> RequestContext.php (source)

   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   * @author Tobias Schultze <http://tobion.de>
  21   */
  22  class RequestContext
  23  {
  24      private $baseUrl;
  25      private $pathInfo;
  26      private $method;
  27      private $host;
  28      private $scheme;
  29      private $httpPort;
  30      private $httpsPort;
  31      private $queryString;
  32  
  33      /**
  34       * @var array
  35       */
  36      private $parameters = array();
  37  
  38      /**
  39       * Constructor.
  40       *
  41       * @param string $baseUrl     The base URL
  42       * @param string $method      The HTTP method
  43       * @param string $host        The HTTP host name
  44       * @param string $scheme      The HTTP scheme
  45       * @param int    $httpPort    The HTTP port
  46       * @param int    $httpsPort   The HTTPS port
  47       * @param string $path        The path
  48       * @param string $queryString The query string
  49       */
  50      public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443, $path = '/', $queryString = '')
  51      {
  52          $this->setBaseUrl($baseUrl);
  53          $this->setMethod($method);
  54          $this->setHost($host);
  55          $this->setScheme($scheme);
  56          $this->setHttpPort($httpPort);
  57          $this->setHttpsPort($httpsPort);
  58          $this->setPathInfo($path);
  59          $this->setQueryString($queryString);
  60      }
  61  
  62      /**
  63       * Updates the RequestContext information based on a HttpFoundation Request.
  64       *
  65       * @param Request $request A Request instance
  66       */
  67      public function fromRequest(Request $request)
  68      {
  69          $this->setBaseUrl($request->getBaseUrl());
  70          $this->setPathInfo($request->getPathInfo());
  71          $this->setMethod($request->getMethod());
  72          $this->setHost($request->getHost());
  73          $this->setScheme($request->getScheme());
  74          $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
  75          $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
  76          $this->setQueryString($request->server->get('QUERY_STRING', ''));
  77      }
  78  
  79      /**
  80       * Gets the base URL.
  81       *
  82       * @return string The base URL
  83       */
  84      public function getBaseUrl()
  85      {
  86          return $this->baseUrl;
  87      }
  88  
  89      /**
  90       * Sets the base URL.
  91       *
  92       * @param string $baseUrl The base URL
  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      public function setMethod($method)
 137      {
 138          $this->method = strtoupper($method);
 139      }
 140  
 141      /**
 142       * Gets the HTTP host.
 143       *
 144       * The host is always lowercased because it must be treated case-insensitive.
 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      public function setHost($host)
 159      {
 160          $this->host = strtolower($host);
 161      }
 162  
 163      /**
 164       * Gets the HTTP scheme.
 165       *
 166       * @return string The HTTP scheme
 167       */
 168      public function getScheme()
 169      {
 170          return $this->scheme;
 171      }
 172  
 173      /**
 174       * Sets the HTTP scheme.
 175       *
 176       * @param string $scheme The HTTP scheme
 177       */
 178      public function setScheme($scheme)
 179      {
 180          $this->scheme = strtolower($scheme);
 181      }
 182  
 183      /**
 184       * Gets the HTTP port.
 185       *
 186       * @return int The HTTP port
 187       */
 188      public function getHttpPort()
 189      {
 190          return $this->httpPort;
 191      }
 192  
 193      /**
 194       * Sets the HTTP port.
 195       *
 196       * @param int $httpPort The HTTP port
 197       */
 198      public function setHttpPort($httpPort)
 199      {
 200          $this->httpPort = (int) $httpPort;
 201      }
 202  
 203      /**
 204       * Gets the HTTPS port.
 205       *
 206       * @return int The HTTPS port
 207       */
 208      public function getHttpsPort()
 209      {
 210          return $this->httpsPort;
 211      }
 212  
 213      /**
 214       * Sets the HTTPS port.
 215       *
 216       * @param int $httpsPort The HTTPS port
 217       */
 218      public function setHttpsPort($httpsPort)
 219      {
 220          $this->httpsPort = (int) $httpsPort;
 221      }
 222  
 223      /**
 224       * Gets the query string.
 225       *
 226       * @return string The query string without the "?"
 227       */
 228      public function getQueryString()
 229      {
 230          return $this->queryString;
 231      }
 232  
 233      /**
 234       * Sets the query string.
 235       *
 236       * @param string $queryString The query string (after "?")
 237       */
 238      public function setQueryString($queryString)
 239      {
 240          // string cast to be fault-tolerant, accepting null
 241          $this->queryString = (string) $queryString;
 242      }
 243  
 244      /**
 245       * Returns the parameters.
 246       *
 247       * @return array The parameters
 248       */
 249      public function getParameters()
 250      {
 251          return $this->parameters;
 252      }
 253  
 254      /**
 255       * Sets the parameters.
 256       *
 257       * @param array $parameters The parameters
 258       *
 259       * @return RequestContext The current instance, implementing a fluent interface
 260       */
 261      public function setParameters(array $parameters)
 262      {
 263          $this->parameters = $parameters;
 264  
 265          return $this;
 266      }
 267  
 268      /**
 269       * Gets a parameter value.
 270       *
 271       * @param string $name A parameter name
 272       *
 273       * @return mixed The parameter value or null if nonexistent
 274       */
 275      public function getParameter($name)
 276      {
 277          return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
 278      }
 279  
 280      /**
 281       * Checks if a parameter value is set for the given parameter.
 282       *
 283       * @param string $name A parameter name
 284       *
 285       * @return bool True if the parameter value is set, false otherwise
 286       */
 287      public function hasParameter($name)
 288      {
 289          return array_key_exists($name, $this->parameters);
 290      }
 291  
 292      /**
 293       * Sets a parameter value.
 294       *
 295       * @param string $name      A parameter name
 296       * @param mixed  $parameter The parameter value
 297       */
 298      public function setParameter($name, $parameter)
 299      {
 300          $this->parameters[$name] = $parameter;
 301      }
 302  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1