validateUploadedFiles($uploadedFiles); if ($body === 'php://input') { $body = new PhpInputStream(); } $this->initialize($uri, $method, $body, $headers); $this->serverParams = $serverParams; $this->uploadedFiles = $uploadedFiles; $this->cookieParams = $cookies; $this->queryParams = $queryParams; $this->parsedBody = $parsedBody; $this->protocol = $protocol; } /** * {@inheritdoc} */ public function getServerParams() { return $this->serverParams; } /** * {@inheritdoc} */ public function getUploadedFiles() { return $this->uploadedFiles; } /** * {@inheritdoc} */ public function withUploadedFiles(array $uploadedFiles) { $this->validateUploadedFiles($uploadedFiles); $new = clone $this; $new->uploadedFiles = $uploadedFiles; return $new; } /** * {@inheritdoc} */ public function getCookieParams() { return $this->cookieParams; } /** * {@inheritdoc} */ public function withCookieParams(array $cookies) { $new = clone $this; $new->cookieParams = $cookies; return $new; } /** * {@inheritdoc} */ public function getQueryParams() { return $this->queryParams; } /** * {@inheritdoc} */ public function withQueryParams(array $query) { $new = clone $this; $new->queryParams = $query; return $new; } /** * {@inheritdoc} */ public function getParsedBody() { return $this->parsedBody; } /** * {@inheritdoc} */ public function withParsedBody($data) { $new = clone $this; $new->parsedBody = $data; return $new; } /** * {@inheritdoc} */ public function getAttributes() { return $this->attributes; } /** * {@inheritdoc} */ public function getAttribute($attribute, $default = null) { if (! array_key_exists($attribute, $this->attributes)) { return $default; } return $this->attributes[$attribute]; } /** * {@inheritdoc} */ public function withAttribute($attribute, $value) { $new = clone $this; $new->attributes[$attribute] = $value; return $new; } /** * {@inheritdoc} */ public function withoutAttribute($attribute) { $new = clone $this; unset($new->attributes[$attribute]); return $new; } /** * Proxy to receive the request method. * * This overrides the parent functionality to ensure the method is never * empty; if no method is present, it returns 'GET'. * * @return string */ public function getMethod() { if (empty($this->method)) { return 'GET'; } return $this->method; } /** * Set the request method. * * Unlike the regular Request implementation, the server-side * normalizes the method to uppercase to ensure consistency * and make checking the method simpler. * * This methods returns a new instance. * * @param string $method * @return self */ public function withMethod($method) { $this->validateMethod($method); $new = clone $this; $new->method = $method; return $new; } /** * Recursively validate the structure in an uploaded files array. * * @param array $uploadedFiles * @throws InvalidArgumentException if any leaf is not an UploadedFileInterface instance. */ private function validateUploadedFiles(array $uploadedFiles) { foreach ($uploadedFiles as $file) { if (is_array($file)) { $this->validateUploadedFiles($file); continue; } if (! $file instanceof UploadedFileInterface) { throw new InvalidArgumentException('Invalid leaf in uploaded files structure'); } } } }