TYPO3  7.6
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 
20 
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(), array $serverParams = array(), 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  {
202  return $this->uploadedFiles;
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 isset($this->attributes[$name]) ? $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  } else {
360  unset($clonedObject->attributes[$name]);
361  return $clonedObject;
362  }
363  }
364 
371  protected function validateUploadedFiles(array $uploadedFiles)
372  {
373  foreach ($uploadedFiles as $file) {
374  if (is_array($file)) {
375  $this->validateUploadedFiles($file);
376  continue;
377  }
378  if (!$file instanceof UploadedFileInterface) {
379  throw new \InvalidArgumentException('Invalid file in uploaded files structure.', 1436717281);
380  }
381  }
382  }
383 }