‪TYPO3CMS  ‪main
ServerRequest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 namespace ‪TYPO3\CMS\Core\Http;
19 
20 use Psr\Http\Message\ServerRequestInterface;
21 use Psr\Http\Message\StreamInterface;
22 use Psr\Http\Message\UploadedFileInterface;
23 use Psr\Http\Message\UriInterface;
24 
38 class ‪ServerRequest extends ‪Request implements ServerRequestInterface
39 {
40  protected array ‪$attributes = [];
41  protected array ‪$cookieParams = [];
42  protected array ‪$queryParams = [];
43  protected array ‪$serverParams = [];
44  protected array ‪$uploadedFiles = [];
45 
49  protected ‪$parsedBody;
50 
62  public function ‪__construct(string|UriInterface|null ‪$uri = null, ‪$method = null, ‪$body = 'php://input', array ‪$headers = [], array ‪$serverParams = [], array ‪$uploadedFiles = null)
63  {
64  if (‪$uploadedFiles !== null) {
65  $this->‪validateUploadedFiles($uploadedFiles);
66  }
67 
68  parent::__construct(‪$uri, ‪$method ?? 'GET', ‪$body, ‪$headers);
69 
70  $this->serverParams = ‪$serverParams;
71  $this->uploadedFiles = ‪$uploadedFiles ?? [];
72  }
73 
81  public function ‪getServerParams(): array
82  {
84  }
85 
94  public function ‪getCookieParams(): array
95  {
97  }
98 
116  public function ‪withCookieParams(array $cookies): ServerRequestInterface
117  {
118  $clonedObject = clone $this;
119  $clonedObject->cookieParams = $cookies;
120  return $clonedObject;
121  }
122 
133  public function ‪getQueryParams(): array
134  {
135  return ‪$this->queryParams;
136  }
137 
160  public function ‪withQueryParams(array $query): ServerRequestInterface
161  {
162  $clonedObject = clone $this;
163  $clonedObject->queryParams = $query;
164  return $clonedObject;
165  }
166 
179  public function ‪getUploadedFiles(): array
180  {
182  }
183 
195  public function ‪withUploadedFiles(array ‪$uploadedFiles): ServerRequestInterface
196  {
197  $this->‪validateUploadedFiles($uploadedFiles);
198  $clonedObject = clone $this;
199  $clonedObject->uploadedFiles = ‪$uploadedFiles;
200  return $clonedObject;
201  }
202 
218  public function ‪getParsedBody()
219  {
220  return ‪$this->parsedBody;
221  }
222 
251  public function ‪withParsedBody($data): ServerRequestInterface
252  {
253  $clonedObject = clone $this;
254  $clonedObject->parsedBody = $data;
255  return $clonedObject;
256  }
257 
269  public function ‪getAttributes(): array
270  {
271  return ‪$this->attributes;
272  }
273 
290  public function ‪getAttribute(string $name, $default = null)
291  {
292  return $this->attributes[$name] ?? $default;
293  }
294 
311  public function ‪withAttribute(string $name, $value): ServerRequestInterface
312  {
313  $clonedObject = clone $this;
314  $clonedObject->attributes[$name] = $value;
315  return $clonedObject;
316  }
317 
333  public function ‪withoutAttribute(string $name): ServerRequestInterface
334  {
335  $clonedObject = clone $this;
336  if (!isset($clonedObject->attributes[$name])) {
337  return $clonedObject;
338  }
339  unset($clonedObject->attributes[$name]);
340  return $clonedObject;
341  }
342 
348  protected function ‪validateUploadedFiles(array ‪$uploadedFiles): void
349  {
350  foreach (‪$uploadedFiles as $file) {
351  if (is_array($file)) {
352  $this->‪validateUploadedFiles($file);
353  continue;
354  }
355  if (!$file instanceof UploadedFileInterface) {
356  throw new \InvalidArgumentException('Invalid file in uploaded files structure.', 1436717281);
357  }
358  }
359  }
360 }
‪TYPO3\CMS\Core\Http\ServerRequest\getAttributes
‪array getAttributes()
Definition: ServerRequest.php:268
‪TYPO3\CMS\Core\Http\ServerRequest\withQueryParams
‪static withQueryParams(array $query)
Definition: ServerRequest.php:159
‪TYPO3\CMS\Core\Http\ServerRequest\$serverParams
‪array $serverParams
Definition: ServerRequest.php:43
‪TYPO3\CMS\Core\Http\ServerRequest\getCookieParams
‪getCookieParams()
Definition: ServerRequest.php:93
‪TYPO3\CMS\Core\Http\ServerRequest\$queryParams
‪array $queryParams
Definition: ServerRequest.php:42
‪TYPO3\CMS\Core\Http\ServerRequest\validateUploadedFiles
‪validateUploadedFiles(array $uploadedFiles)
Definition: ServerRequest.php:347
‪TYPO3\CMS\Core\Http\ServerRequest\getParsedBody
‪array object null getParsedBody()
Definition: ServerRequest.php:217
‪TYPO3\CMS\Core\Http\Request\$uri
‪UriInterface $uri
Definition: Request.php:80
‪TYPO3\CMS\Core\Http\ServerRequest\withUploadedFiles
‪static withUploadedFiles(array $uploadedFiles)
Definition: ServerRequest.php:194
‪TYPO3\CMS\Core\Http\Request\$method
‪string $method
Definition: Request.php:44
‪TYPO3\CMS\Core\Http\ServerRequest\__construct
‪__construct(string|UriInterface|null $uri=null, $method=null, $body='php://input', array $headers=[], array $serverParams=[], array $uploadedFiles=null)
Definition: ServerRequest.php:61
‪TYPO3\CMS\Core\Http\ServerRequest\getQueryParams
‪getQueryParams()
Definition: ServerRequest.php:132
‪TYPO3\CMS\Core\Http\ServerRequest\withoutAttribute
‪static withoutAttribute(string $name)
Definition: ServerRequest.php:332
‪TYPO3\CMS\Core\Http\Message\$body
‪StreamInterface $body
Definition: Message.php:53
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Http\ServerRequest\withCookieParams
‪static withCookieParams(array $cookies)
Definition: ServerRequest.php:115
‪TYPO3\CMS\Core\Http\ServerRequest\getUploadedFiles
‪array getUploadedFiles()
Definition: ServerRequest.php:178
‪TYPO3\CMS\Core\Http\ServerRequest\$uploadedFiles
‪array $uploadedFiles
Definition: ServerRequest.php:44
‪TYPO3\CMS\Core\Http\ServerRequest\withParsedBody
‪static withParsedBody($data)
Definition: ServerRequest.php:250
‪TYPO3\CMS\Core\Http\ServerRequest\getServerParams
‪getServerParams()
Definition: ServerRequest.php:80
‪TYPO3\CMS\Core\Http\ServerRequest\$parsedBody
‪array object null $parsedBody
Definition: ServerRequest.php:48
‪TYPO3\CMS\Core\Http\ServerRequest\getAttribute
‪mixed getAttribute(string $name, $default=null)
Definition: ServerRequest.php:289
‪TYPO3\CMS\Core\Http\ServerRequest\$cookieParams
‪array $cookieParams
Definition: ServerRequest.php:41
‪TYPO3\CMS\Core\Http\ServerRequest\$attributes
‪array $attributes
Definition: ServerRequest.php:40
‪TYPO3\CMS\Core\Http\Request
Definition: Request.php:35
‪TYPO3\CMS\Core\Http\Message\$headers
‪array $headers
Definition: Message.php:42
‪TYPO3\CMS\Core\Http\ServerRequest\withAttribute
‪static withAttribute(string $name, $value)
Definition: ServerRequest.php:310
‪TYPO3\CMS\Core\Http
Definition: AbstractApplication.php:18