Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Request.php
001 <?php
002
003 namespace GuzzleHttp\Psr7;
004
005 use InvalidArgumentException;
006 use Psr\Http\Message\RequestInterface;
007 use Psr\Http\Message\StreamInterface;
008 use Psr\Http\Message\UriInterface;
009
010 /**
011 * PSR-7 request implementation.
012 */
013 class Request implements RequestInterface
014 {
015 use MessageTrait;
016
017 /** @var string */
018 private $method;
019
020 /** @var string|null */
021 private $requestTarget;
022
023 /** @var UriInterface */
024 private $uri;
025
026 /**
027 * @param string $method HTTP method
028 * @param string|UriInterface $uri URI
029 * @param array $headers Request headers
030 * @param string|resource|StreamInterface|null $body Request body
031 * @param string $version Protocol version
032 */
033 public function __construct(
034 $method,
035 $uri,
036 array $headers = [],
037 $body = null,
038 $version = '1.1'
039 ) {
040 $this->assertMethod($method);
041 if (!($uri instanceof UriInterface)) {
042 $uri = new Uri($uri);
043 }
044
045 $this->method = strtoupper($method);
046 $this->uri = $uri;
047 $this->setHeaders($headers);
048 $this->protocol = $version;
049
050 if (!isset($this->headerNames['host'])) {
051 $this->updateHostFromUri();
052 }
053
054 if ($body !== '' && $body !== null) {
055 $this->stream = Utils::streamFor($body);
056 }
057 }
058
059 public function getRequestTarget()
060 {
061 if ($this->requestTarget !== null) {
062 return $this->requestTarget;
063 }
064
065 $target = $this->uri->getPath();
066 if ($target == '') {
067 $target = '/';
068 }
069 if ($this->uri->getQuery() != '') {
070 $target .= '?' . $this->uri->getQuery();
071 }
072
073 return $target;
074 }
075
076 public function withRequestTarget($requestTarget)
077 {
078 if (preg_match('#\s#', $requestTarget)) {
079 throw new InvalidArgumentException(
080 'Invalid request target provided; cannot contain whitespace'
081 );
082 }
083
084 $new = clone $this;
085 $new->requestTarget = $requestTarget;
086 return $new;
087 }
088
089 public function getMethod()
090 {
091 return $this->method;
092 }
093
094 public function withMethod($method)
095 {
096 $this->assertMethod($method);
097 $new = clone $this;
098 $new->method = strtoupper($method);
099 return $new;
100 }
101
102 public function getUri()
103 {
104 return $this->uri;
105 }
106
107 public function withUri(UriInterface $uri, $preserveHost = false)
108 {
109 if ($uri === $this->uri) {
110 return $this;
111 }
112
113 $new = clone $this;
114 $new->uri = $uri;
115
116 if (!$preserveHost || !isset($this->headerNames['host'])) {
117 $new->updateHostFromUri();
118 }
119
120 return $new;
121 }
122
123 private function updateHostFromUri()
124 {
125 $host = $this->uri->getHost();
126
127 if ($host == '') {
128 return;
129 }
130
131 if (($port = $this->uri->getPort()) !== null) {
132 $host .= ':' . $port;
133 }
134
135 if (isset($this->headerNames['host'])) {
136 $header = $this->headerNames['host'];
137 } else {
138 $header = 'Host';
139 $this->headerNames['host'] = 'Host';
140 }
141 // Ensure Host is the first header.
142 // See: http://tools.ietf.org/html/rfc7230#section-5.4
143 $this->headers = [$header => [$host]] + $this->headers;
144 }
145
146 private function assertMethod($method)
147 {
148 if (!is_string($method) || $method === '') {
149 throw new \InvalidArgumentException('Method must be a non-empty string.');
150 }
151 }
152 }
153