‪TYPO3CMS  10.4
ServerRequest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Core\Http;
17 
18 use Psr\Http\Message\ServerRequestInterface;
19 use Psr\Http\Message\StreamInterface;
20 use Psr\Http\Message\UploadedFileInterface;
21 use Psr\Http\Message\UriInterface;
22 
36 class ‪ServerRequest extends ‪Request implements ServerRequestInterface
37 {
41  protected ‪$attributes = [];
42 
46  protected ‪$cookieParams = [];
47 
51  protected ‪$parsedBody;
52 
56  protected ‪$queryParams = [];
57 
61  protected ‪$serverParams = [];
62 
66  protected ‪$uploadedFiles = [];
67 
79  public function ‪__construct(‪$uri = null, ‪$method = null, ‪$body = 'php://input', array ‪$headers = [], array ‪$serverParams = [], array ‪$uploadedFiles = null)
80  {
81  if (‪$uploadedFiles !== null) {
83  }
84 
85  parent::__construct(‪$uri, ‪$method, ‪$body, ‪$headers);
86 
87  $this->serverParams = ‪$serverParams;
88  $this->uploadedFiles = ‪$uploadedFiles;
89  }
90 
100  public function ‪getServerParams()
101  {
102  return ‪$this->serverParams;
103  }
104 
115  public function ‪getCookieParams()
116  {
117  return ‪$this->cookieParams;
118  }
119 
137  public function ‪withCookieParams(array $cookies)
138  {
139  $clonedObject = clone $this;
140  $clonedObject->cookieParams = $cookies;
141  return $clonedObject;
142  }
143 
156  public function ‪getQueryParams()
157  {
158  return ‪$this->queryParams;
159  }
160 
183  public function ‪withQueryParams(array $query)
184  {
185  $clonedObject = clone $this;
186  $clonedObject->queryParams = $query;
187  return $clonedObject;
188  }
189 
202  public function ‪getUploadedFiles()
203  {
205  }
206 
218  public function ‪withUploadedFiles(array ‪$uploadedFiles)
219  {
220  $this->‪validateUploadedFiles($uploadedFiles);
221  $clonedObject = clone $this;
222  $clonedObject->uploadedFiles = ‪$uploadedFiles;
223  return $clonedObject;
224  }
225 
241  public function ‪getParsedBody()
242  {
243  return ‪$this->parsedBody;
244  }
245 
274  public function ‪withParsedBody($data)
275  {
276  $clonedObject = clone $this;
277  $clonedObject->parsedBody = $data;
278  return $clonedObject;
279  }
280 
292  public function ‪getAttributes()
293  {
294  return ‪$this->attributes;
295  }
296 
313  public function ‪getAttribute($name, $default = null)
314  {
315  return $this->attributes[$name] ?? $default;
316  }
317 
334  public function ‪withAttribute($name, $value)
335  {
336  $clonedObject = clone $this;
337  $clonedObject->attributes[$name] = $value;
338  return $clonedObject;
339  }
340 
356  public function ‪withoutAttribute($name)
357  {
358  $clonedObject = clone $this;
359  if (!isset($clonedObject->attributes[$name])) {
360  return $clonedObject;
361  }
362  unset($clonedObject->attributes[$name]);
363  return $clonedObject;
364  }
365 
372  protected function ‪validateUploadedFiles(array ‪$uploadedFiles)
373  {
374  foreach (‪$uploadedFiles as $file) {
375  if (is_array($file)) {
376  $this->‪validateUploadedFiles($file);
377  continue;
378  }
379  if (!$file instanceof UploadedFileInterface) {
380  throw new \InvalidArgumentException('Invalid file in uploaded files structure.', 1436717281);
381  }
382  }
383  }
384 }
‪TYPO3\CMS\Core\Http\ServerRequest\getAttributes
‪array getAttributes()
Definition: ServerRequest.php:286
‪TYPO3\CMS\Core\Http\ServerRequest\getCookieParams
‪array getCookieParams()
Definition: ServerRequest.php:109
‪TYPO3\CMS\Core\Http\ServerRequest\withAttribute
‪static withAttribute($name, $value)
Definition: ServerRequest.php:328
‪TYPO3\CMS\Core\Http\ServerRequest\withQueryParams
‪static withQueryParams(array $query)
Definition: ServerRequest.php:177
‪TYPO3\CMS\Core\Http\ServerRequest\$serverParams
‪array $serverParams
Definition: ServerRequest.php:56
‪TYPO3\CMS\Core\Http\ServerRequest\getQueryParams
‪array getQueryParams()
Definition: ServerRequest.php:150
‪TYPO3\CMS\Core\Http\ServerRequest\$queryParams
‪array $queryParams
Definition: ServerRequest.php:52
‪TYPO3\CMS\Core\Http\ServerRequest\validateUploadedFiles
‪validateUploadedFiles(array $uploadedFiles)
Definition: ServerRequest.php:366
‪TYPO3\CMS\Core\Http\ServerRequest\withoutAttribute
‪static withoutAttribute($name)
Definition: ServerRequest.php:350
‪TYPO3\CMS\Core\Http\ServerRequest\getParsedBody
‪array object null getParsedBody()
Definition: ServerRequest.php:235
‪TYPO3\CMS\Core\Http\Request\$uri
‪UriInterface $uri
Definition: Request.php:76
‪TYPO3\CMS\Core\Http\ServerRequest\withUploadedFiles
‪static withUploadedFiles(array $uploadedFiles)
Definition: ServerRequest.php:212
‪TYPO3\CMS\Core\Http\Request\$method
‪string $method
Definition: Request.php:43
‪TYPO3\CMS\Core\Http\Message\$body
‪StreamInterface $body
Definition: Message.php:51
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Core\Http\ServerRequest\withCookieParams
‪static withCookieParams(array $cookies)
Definition: ServerRequest.php:131
‪TYPO3\CMS\Core\Http\ServerRequest\getUploadedFiles
‪array getUploadedFiles()
Definition: ServerRequest.php:196
‪TYPO3\CMS\Core\Http\ServerRequest\$uploadedFiles
‪array $uploadedFiles
Definition: ServerRequest.php:60
‪TYPO3\CMS\Core\Http\ServerRequest\withParsedBody
‪static withParsedBody($data)
Definition: ServerRequest.php:268
‪TYPO3\CMS\Core\Http\ServerRequest\$cookieParams
‪array $cookieParams
Definition: ServerRequest.php:44
‪TYPO3\CMS\Core\Http\ServerRequest\$attributes
‪array $attributes
Definition: ServerRequest.php:40
‪TYPO3\CMS\Core\Http\ServerRequest\getAttribute
‪mixed getAttribute($name, $default=null)
Definition: ServerRequest.php:307
‪TYPO3\CMS\Core\Http\ServerRequest\$parsedBody
‪array $parsedBody
Definition: ServerRequest.php:48
‪TYPO3\CMS\Core\Http\Request
Definition: Request.php:33
‪TYPO3\CMS\Core\Http\ServerRequest\getServerParams
‪array getServerParams()
Definition: ServerRequest.php:94
‪TYPO3\CMS\Core\Http\Message\$headers
‪array $headers
Definition: Message.php:40
‪TYPO3\CMS\Core\Http
Definition: AbstractApplication.php:18
‪TYPO3\CMS\Core\Http\ServerRequest\__construct
‪__construct($uri=null, $method=null, $body='php://input', array $headers=[], array $serverParams=[], array $uploadedFiles=null)
Definition: ServerRequest.php:73