Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

RequestContext.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 7.87 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\Routing;
 013   
 014  use Symfony\Component\HttpFoundation\Request;
 015   
 016  /**
 017   * Holds information about the current request.
 018   *
 019   * This class implements a fluent interface.
 020   *
 021   * @author Fabien Potencier <fabien@symfony.com>
 022   * @author Tobias Schultze <http://tobion.de>
 023   */
 024  class RequestContext
 025  {
 026      private $baseUrl;
 027      private $pathInfo;
 028      private $method;
 029      private $host;
 030      private $scheme;
 031      private $httpPort;
 032      private $httpsPort;
 033      private $queryString;
 034   
 035      /**
 036       * @var array
 037       */
 038      private $parameters = array();
 039   
 040      /**
 041       * Constructor.
 042       *
 043       * @param string $baseUrl     The base URL
 044       * @param string $method      The HTTP method
 045       * @param string $host        The HTTP host name
 046       * @param string $scheme      The HTTP scheme
 047       * @param int    $httpPort    The HTTP port
 048       * @param int    $httpsPort   The HTTPS port
 049       * @param string $path        The path
 050       * @param string $queryString The query string
 051       */
 052      public function __construct($baseUrl = '', $method = 'GET', $host = 'localhost', $scheme = 'http', $httpPort = 80, $httpsPort = 443, $path = '/', $queryString = '')
 053      {
 054          $this->setBaseUrl($baseUrl);
 055          $this->setMethod($method);
 056          $this->setHost($host);
 057          $this->setScheme($scheme);
 058          $this->setHttpPort($httpPort);
 059          $this->setHttpsPort($httpsPort);
 060          $this->setPathInfo($path);
 061          $this->setQueryString($queryString);
 062      }
 063   
 064      /**
 065       * Updates the RequestContext information based on a HttpFoundation Request.
 066       *
 067       * @param Request $request A Request instance
 068       *
 069       * @return RequestContext The current instance, implementing a fluent interface
 070       */
 071      public function fromRequest(Request $request)
 072      {
 073          $this->setBaseUrl($request->getBaseUrl());
 074          $this->setPathInfo($request->getPathInfo());
 075          $this->setMethod($request->getMethod());
 076          $this->setHost($request->getHost());
 077          $this->setScheme($request->getScheme());
 078          $this->setHttpPort($request->isSecure() ? $this->httpPort : $request->getPort());
 079          $this->setHttpsPort($request->isSecure() ? $request->getPort() : $this->httpsPort);
 080          $this->setQueryString($request->server->get('QUERY_STRING', ''));
 081   
 082          return $this;
 083      }
 084   
 085      /**
 086       * Gets the base URL.
 087       *
 088       * @return string The base URL
 089       */
 090      public function getBaseUrl()
 091      {
 092          return $this->baseUrl;
 093      }
 094   
 095      /**
 096       * Sets the base URL.
 097       *
 098       * @param string $baseUrl The base URL
 099       *
 100       * @return RequestContext The current instance, implementing a fluent interface
 101       */
 102      public function setBaseUrl($baseUrl)
 103      {
 104          $this->baseUrl = $baseUrl;
 105   
 106          return $this;
 107      }
 108   
 109      /**
 110       * Gets the path info.
 111       *
 112       * @return string The path info
 113       */
 114      public function getPathInfo()
 115      {
 116          return $this->pathInfo;
 117      }
 118   
 119      /**
 120       * Sets the path info.
 121       *
 122       * @param string $pathInfo The path info
 123       *
 124       * @return RequestContext The current instance, implementing a fluent interface
 125       */
 126      public function setPathInfo($pathInfo)
 127      {
 128          $this->pathInfo = $pathInfo;
 129   
 130          return $this;
 131      }
 132   
 133      /**
 134       * Gets the HTTP method.
 135       *
 136       * The method is always an uppercased string.
 137       *
 138       * @return string The HTTP method
 139       */
 140      public function getMethod()
 141      {
 142          return $this->method;
 143      }
 144   
 145      /**
 146       * Sets the HTTP method.
 147       *
 148       * @param string $method The HTTP method
 149       *
 150       * @return RequestContext The current instance, implementing a fluent interface
 151       */
 152      public function setMethod($method)
 153      {
 154          $this->method = strtoupper($method);
 155   
 156          return $this;
 157      }
 158   
 159      /**
 160       * Gets the HTTP host.
 161       *
 162       * The host is always lowercased because it must be treated case-insensitive.
 163       *
 164       * @return string The HTTP host
 165       */
 166      public function getHost()
 167      {
 168          return $this->host;
 169      }
 170   
 171      /**
 172       * Sets the HTTP host.
 173       *
 174       * @param string $host The HTTP host
 175       *
 176       * @return RequestContext The current instance, implementing a fluent interface
 177       */
 178      public function setHost($host)
 179      {
 180          $this->host = strtolower($host);
 181   
 182          return $this;
 183      }
 184   
 185      /**
 186       * Gets the HTTP scheme.
 187       *
 188       * @return string The HTTP scheme
 189       */
 190      public function getScheme()
 191      {
 192          return $this->scheme;
 193      }
 194   
 195      /**
 196       * Sets the HTTP scheme.
 197       *
 198       * @param string $scheme The HTTP scheme
 199       *
 200       * @return RequestContext The current instance, implementing a fluent interface
 201       */
 202      public function setScheme($scheme)
 203      {
 204          $this->scheme = strtolower($scheme);
 205   
 206          return $this;
 207      }
 208   
 209      /**
 210       * Gets the HTTP port.
 211       *
 212       * @return int The HTTP port
 213       */
 214      public function getHttpPort()
 215      {
 216          return $this->httpPort;
 217      }
 218   
 219      /**
 220       * Sets the HTTP port.
 221       *
 222       * @param int $httpPort The HTTP port
 223       *
 224       * @return RequestContext The current instance, implementing a fluent interface
 225       */
 226      public function setHttpPort($httpPort)
 227      {
 228          $this->httpPort = (int) $httpPort;
 229   
 230          return $this;
 231      }
 232   
 233      /**
 234       * Gets the HTTPS port.
 235       *
 236       * @return int The HTTPS port
 237       */
 238      public function getHttpsPort()
 239      {
 240          return $this->httpsPort;
 241      }
 242   
 243      /**
 244       * Sets the HTTPS port.
 245       *
 246       * @param int $httpsPort The HTTPS port
 247       *
 248       * @return RequestContext The current instance, implementing a fluent interface
 249       */
 250      public function setHttpsPort($httpsPort)
 251      {
 252          $this->httpsPort = (int) $httpsPort;
 253   
 254          return $this;
 255      }
 256   
 257      /**
 258       * Gets the query string.
 259       *
 260       * @return string The query string without the "?"
 261       */
 262      public function getQueryString()
 263      {
 264          return $this->queryString;
 265      }
 266   
 267      /**
 268       * Sets the query string.
 269       *
 270       * @param string $queryString The query string (after "?")
 271       *
 272       * @return RequestContext The current instance, implementing a fluent interface
 273       */
 274      public function setQueryString($queryString)
 275      {
 276          // string cast to be fault-tolerant, accepting null
 277          $this->queryString = (string) $queryString;
 278   
 279          return $this;
 280      }
 281   
 282      /**
 283       * Returns the parameters.
 284       *
 285       * @return array The parameters
 286       */
 287      public function getParameters()
 288      {
 289          return $this->parameters;
 290      }
 291   
 292      /**
 293       * Sets the parameters.
 294       *
 295       * @param array $parameters The parameters
 296       *
 297       * @return RequestContext The current instance, implementing a fluent interface
 298       */
 299      public function setParameters(array $parameters)
 300      {
 301          $this->parameters = $parameters;
 302   
 303          return $this;
 304      }
 305   
 306      /**
 307       * Gets a parameter value.
 308       *
 309       * @param string $name A parameter name
 310       *
 311       * @return mixed The parameter value or null if nonexistent
 312       */
 313      public function getParameter($name)
 314      {
 315          return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
 316      }
 317   
 318      /**
 319       * Checks if a parameter value is set for the given parameter.
 320       *
 321       * @param string $name A parameter name
 322       *
 323       * @return bool True if the parameter value is set, false otherwise
 324       */
 325      public function hasParameter($name)
 326      {
 327          return array_key_exists($name, $this->parameters);
 328      }
 329   
 330      /**
 331       * Sets a parameter value.
 332       *
 333       * @param string $name      A parameter name
 334       * @param mixed  $parameter The parameter value
 335       *
 336       * @return RequestContext The current instance, implementing a fluent interface
 337       */
 338      public function setParameter($name, $parameter)
 339      {
 340          $this->parameters[$name] = $parameter;
 341   
 342          return $this;
 343      }
 344  }
 345