‪TYPO3CMS  9.5
ServerRequest.php
Go to the documentation of this file.
1 <?php
2 namespace ‪TYPO3\CMS\Core\Http;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Psr\Http\Message\ServerRequestInterface;
18 use Psr\Http\Message\StreamInterface;
19 use Psr\Http\Message\UploadedFileInterface;
20 
34 class ‪ServerRequest extends ‪Request implements ServerRequestInterface
35 {
39  protected ‪$attributes = [];
40 
44  protected ‪$cookieParams = [];
45 
49  protected ‪$parsedBody;
50 
54  protected ‪$queryParams = [];
55 
59  protected ‪$serverParams = [];
60 
64  protected ‪$uploadedFiles = [];
65 
77  public function ‪__construct(‪$uri = null, ‪$method = null, ‪$body = 'php://input', array ‪$headers = [], array ‪$serverParams = [], array ‪$uploadedFiles = null)
78  {
79  if (‪$uploadedFiles !== null) {
81  }
82 
83  parent::__construct(‪$uri, ‪$method, ‪$body, ‪$headers);
84 
85  $this->serverParams = ‪$serverParams;
86  $this->uploadedFiles = ‪$uploadedFiles;
87  }
88 
98  public function ‪getServerParams()
99  {
100  return ‪$this->serverParams;
101  }
102 
113  public function ‪getCookieParams()
114  {
115  return ‪$this->cookieParams;
116  }
117 
135  public function ‪withCookieParams(array $cookies)
136  {
137  $clonedObject = clone $this;
138  $clonedObject->cookieParams = $cookies;
139  return $clonedObject;
140  }
141 
154  public function ‪getQueryParams()
155  {
156  return ‪$this->queryParams;
157  }
158 
181  public function ‪withQueryParams(array $query)
182  {
183  $clonedObject = clone $this;
184  $clonedObject->queryParams = $query;
185  return $clonedObject;
186  }
187 
200  public function ‪getUploadedFiles()
201  {
203  }
204 
216  public function ‪withUploadedFiles(array ‪$uploadedFiles)
217  {
218  $this->‪validateUploadedFiles($uploadedFiles);
219  $clonedObject = clone $this;
220  $clonedObject->uploadedFiles = ‪$uploadedFiles;
221  return $clonedObject;
222  }
223 
239  public function ‪getParsedBody()
240  {
241  return ‪$this->parsedBody;
242  }
243 
272  public function ‪withParsedBody($data)
273  {
274  $clonedObject = clone $this;
275  $clonedObject->parsedBody = $data;
276  return $clonedObject;
277  }
278 
290  public function ‪getAttributes()
291  {
292  return ‪$this->attributes;
293  }
294 
311  public function ‪getAttribute($name, $default = null)
312  {
313  return $this->attributes[$name] ?? $default;
314  }
315 
332  public function ‪withAttribute($name, $value)
333  {
334  $clonedObject = clone $this;
335  $clonedObject->attributes[$name] = $value;
336  return $clonedObject;
337  }
338 
354  public function ‪withoutAttribute($name)
355  {
356  $clonedObject = clone $this;
357  if (!isset($clonedObject->attributes[$name])) {
358  return $clonedObject;
359  }
360  unset($clonedObject->attributes[$name]);
361  return $clonedObject;
362  }
363 
370  protected function ‪validateUploadedFiles(array ‪$uploadedFiles)
371  {
372  foreach (‪$uploadedFiles as $file) {
373  if (is_array($file)) {
374  $this->‪validateUploadedFiles($file);
375  continue;
376  }
377  if (!$file instanceof UploadedFileInterface) {
378  throw new \InvalidArgumentException('Invalid file in uploaded files structure.', 1436717281);
379  }
380  }
381  }
382 }
‪TYPO3\CMS\Core\Http\ServerRequest\getAttributes
‪array getAttributes()
Definition: ServerRequest.php:284
‪TYPO3\CMS\Core\Http\ServerRequest\getCookieParams
‪array getCookieParams()
Definition: ServerRequest.php:107
‪TYPO3\CMS\Core\Http\ServerRequest\withAttribute
‪static withAttribute($name, $value)
Definition: ServerRequest.php:326
‪TYPO3\CMS\Core\Http\ServerRequest\withQueryParams
‪static withQueryParams(array $query)
Definition: ServerRequest.php:175
‪TYPO3\CMS\Core\Http\ServerRequest\$serverParams
‪array $serverParams
Definition: ServerRequest.php:54
‪TYPO3\CMS\Core\Http\ServerRequest\getQueryParams
‪array getQueryParams()
Definition: ServerRequest.php:148
‪TYPO3\CMS\Core\Http\ServerRequest\$queryParams
‪array $queryParams
Definition: ServerRequest.php:50
‪TYPO3\CMS\Core\Http\ServerRequest\validateUploadedFiles
‪validateUploadedFiles(array $uploadedFiles)
Definition: ServerRequest.php:364
‪TYPO3\CMS\Core\Http\ServerRequest\withoutAttribute
‪static withoutAttribute($name)
Definition: ServerRequest.php:348
‪TYPO3\CMS\Core\Http\ServerRequest\getParsedBody
‪array object null getParsedBody()
Definition: ServerRequest.php:233
‪TYPO3\CMS\Core\Http\Request\$uri
‪UriInterface $uri
Definition: Request.php:75
‪TYPO3\CMS\Core\Http\ServerRequest\withUploadedFiles
‪static withUploadedFiles(array $uploadedFiles)
Definition: ServerRequest.php:210
‪TYPO3\CMS\Core\Http\Request\$method
‪string $method
Definition: Request.php:42
‪TYPO3\CMS\Core\Http\Message\$body
‪StreamInterface $body
Definition: Message.php:50
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:35
‪TYPO3\CMS\Core\Http\ServerRequest\withCookieParams
‪static withCookieParams(array $cookies)
Definition: ServerRequest.php:129
‪TYPO3\CMS\Core\Http\ServerRequest\getUploadedFiles
‪array getUploadedFiles()
Definition: ServerRequest.php:194
‪TYPO3\CMS\Core\Http\ServerRequest\$uploadedFiles
‪array $uploadedFiles
Definition: ServerRequest.php:58
‪TYPO3\CMS\Core\Http\ServerRequest\withParsedBody
‪static withParsedBody($data)
Definition: ServerRequest.php:266
‪TYPO3\CMS\Core\Http\ServerRequest\$cookieParams
‪array $cookieParams
Definition: ServerRequest.php:42
‪TYPO3\CMS\Core\Http\ServerRequest\$attributes
‪array $attributes
Definition: ServerRequest.php:38
‪TYPO3\CMS\Core\Http\ServerRequest\getAttribute
‪mixed getAttribute($name, $default=null)
Definition: ServerRequest.php:305
‪TYPO3\CMS\Core\Http\ServerRequest\$parsedBody
‪array $parsedBody
Definition: ServerRequest.php:46
‪TYPO3\CMS\Core\Http\Request
Definition: Request.php:32
‪TYPO3\CMS\Core\Http\ServerRequest\getServerParams
‪array getServerParams()
Definition: ServerRequest.php:92
‪TYPO3\CMS\Core\Http\Message\$headers
‪array $headers
Definition: Message.php:39
‪TYPO3\CMS\Core\Http
Definition: AbstractApplication.php:3
‪TYPO3\CMS\Core\Http\ServerRequest\__construct
‪__construct($uri=null, $method=null, $body='php://input', array $headers=[], array $serverParams=[], array $uploadedFiles=null)
Definition: ServerRequest.php:71