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

Request.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 4.55 KiB


 001  <?php
 002  namespace GuzzleHttp\Message;
 003   
 004  use GuzzleHttp\Collection;
 005  use GuzzleHttp\Event\HasEmitterTrait;
 006  use GuzzleHttp\Subscriber\Prepare;
 007  use GuzzleHttp\Url;
 008   
 009  /**
 010   * HTTP request class to send requests
 011   */
 012  class Request extends AbstractMessage implements RequestInterface
 013  {
 014      use HasEmitterTrait;
 015   
 016      /** @var Url HTTP Url */
 017      private $url;
 018   
 019      /** @var string HTTP method */
 020      private $method;
 021   
 022      /** @var Collection Transfer options */
 023      private $transferOptions;
 024   
 025      /**
 026       * @param string           $method  HTTP method
 027       * @param string|Url       $url     HTTP URL to connect to. The URI scheme,
 028       *   host header, and URI are parsed from the full URL. If query string
 029       *   parameters are present they will be parsed as well.
 030       * @param array|Collection $headers HTTP headers
 031       * @param mixed            $body    Body to send with the request
 032       * @param array            $options Array of options to use with the request
 033       *     - emitter: Event emitter to use with the request
 034       */
 035      public function __construct(
 036          $method,
 037          $url,
 038          $headers = [],
 039          $body = null,
 040          array $options = []
 041      ) {
 042          $this->setUrl($url);
 043          $this->method = strtoupper($method);
 044          $this->handleOptions($options);
 045          $this->transferOptions = new Collection($options);
 046          $this->addPrepareEvent();
 047   
 048          if ($body !== null) {
 049              $this->setBody($body);
 050          }
 051   
 052          if ($headers) {
 053              foreach ($headers as $key => $value) {
 054                  $this->addHeader($key, $value);
 055              }
 056          }
 057      }
 058   
 059      public function __clone()
 060      {
 061          if ($this->emitter) {
 062              $this->emitter = clone $this->emitter;
 063          }
 064          $this->transferOptions = clone $this->transferOptions;
 065          $this->url = clone $this->url;
 066      }
 067   
 068      public function setUrl($url)
 069      {
 070          $this->url = $url instanceof Url ? $url : Url::fromString($url);
 071          $this->updateHostHeaderFromUrl();
 072      }
 073   
 074      public function getUrl()
 075      {
 076          return (string) $this->url;
 077      }
 078   
 079      public function setQuery($query)
 080      {
 081          $this->url->setQuery($query);
 082      }
 083   
 084      public function getQuery()
 085      {
 086          return $this->url->getQuery();
 087      }
 088   
 089      public function setMethod($method)
 090      {
 091          $this->method = strtoupper($method);
 092      }
 093   
 094      public function getMethod()
 095      {
 096          return $this->method;
 097      }
 098   
 099      public function getScheme()
 100      {
 101          return $this->url->getScheme();
 102      }
 103   
 104      public function setScheme($scheme)
 105      {
 106          $this->url->setScheme($scheme);
 107      }
 108   
 109      public function getPort()
 110      {
 111          return $this->url->getPort();
 112      }
 113   
 114      public function setPort($port)
 115      {
 116          $this->url->setPort($port);
 117          $this->updateHostHeaderFromUrl();
 118      }
 119   
 120      public function getHost()
 121      {
 122          return $this->url->getHost();
 123      }
 124   
 125      public function setHost($host)
 126      {
 127          $this->url->setHost($host);
 128          $this->updateHostHeaderFromUrl();
 129      }
 130   
 131      public function getPath()
 132      {
 133          return '/' . ltrim($this->url->getPath(), '/');
 134      }
 135   
 136      public function setPath($path)
 137      {
 138          $this->url->setPath($path);
 139      }
 140   
 141      public function getResource()
 142      {
 143          $resource = $this->getPath();
 144          if ($query = (string) $this->url->getQuery()) {
 145              $resource .= '?' . $query;
 146          }
 147   
 148          return $resource;
 149      }
 150   
 151      public function getConfig()
 152      {
 153          return $this->transferOptions;
 154      }
 155   
 156      protected function handleOptions(array &$options)
 157      {
 158          parent::handleOptions($options);
 159          // Use a custom emitter if one is specified, and remove it from
 160          // options that are exposed through getConfig()
 161          if (isset($options['emitter'])) {
 162              $this->emitter = $options['emitter'];
 163              unset($options['emitter']);
 164          }
 165      }
 166   
 167      /**
 168       * Adds a subscriber that ensures a request's body is prepared before
 169       * sending.
 170       */
 171      private function addPrepareEvent()
 172      {
 173          static $subscriber;
 174          if (!$subscriber) {
 175              $subscriber = new Prepare();
 176          }
 177   
 178          $this->getEmitter()->attach($subscriber);
 179      }
 180   
 181      private function updateHostHeaderFromUrl()
 182      {
 183          $port = $this->url->getPort();
 184          $scheme = $this->url->getScheme();
 185          if ($host = $this->url->getHost()) {
 186              if (($port == 80 && $scheme == 'http') ||
 187                  ($port == 443 && $scheme == 'https')
 188              ) {
 189                  $this->setHeader('Host', $host);
 190              } else {
 191                  $this->setHeader('Host', "{$host}:{$port}");
 192              }
 193          }
 194      }
 195  }
 196