89 foreach ($files as
$key => $value) {
91 $normalized[
$key] = $value;
92 } elseif (is_array($value) && isset($value[
'tmp_name'])) {
93 $normalized[
$key] = self::createUploadedFileFromSpec($value);
94 } elseif (is_array($value)) {
95 $normalized[
$key] = self::normalizeFiles($value);
116 if (is_array($value[
'tmp_name'])) {
117 return self::normalizeNestedFileSpec($value);
122 (
int) $value[
'size'],
123 (
int) $value[
'error'],
140 $normalizedFiles = [];
142 foreach (array_keys(
$files[
'tmp_name']) as
$key) {
150 $normalizedFiles[
$key] = self::createUploadedFileFromSpec($spec);
153 return $normalizedFiles;
169 $headers = function_exists(
'getallheaders') ? getallheaders() : [];
170 $uri = self::getUriFromGlobals();
176 return $serverRequest
178 ->withQueryParams(
$_GET)
180 ->withUploadedFiles(self::normalizeFiles($_FILES));
195 $hostHeaderParts = explode(
':',
$_SERVER[
'HTTP_HOST']);
196 $uri =
$uri->withHost($hostHeaderParts[0]);
197 if (isset($hostHeaderParts[1])) {
199 $uri =
$uri->withPort($hostHeaderParts[1]);
201 } elseif (isset(
$_SERVER[
'SERVER_NAME'])) {
203 } elseif (isset(
$_SERVER[
'SERVER_ADDR'])) {
207 if (!$hasPort && isset(
$_SERVER[
'SERVER_PORT'])) {
212 if (isset(
$_SERVER[
'REQUEST_URI'])) {
213 $requestUriParts = explode(
'?',
$_SERVER[
'REQUEST_URI']);
214 $uri =
$uri->withPath($requestUriParts[0]);
215 if (isset($requestUriParts[1])) {
217 $uri =
$uri->withQuery($requestUriParts[1]);
221 if (!$hasQuery && isset(
$_SERVER[
'QUERY_STRING'])) {
270 $new->cookieParams = $cookies;
289 $new->queryParams =
$query;
308 $new->parsedBody =
$data;
326 if (
false === array_key_exists($attribute, $this->attributes)) {
330 return $this->attributes[$attribute];
339 $new->attributes[$attribute] = $value;
349 if (
false === array_key_exists($attribute, $this->attributes)) {
354 unset($new->attributes[$attribute]);
__construct( $method, $uri, array $headers=[], $body=null, $version='1.1', array $serverParams=[])
static createUploadedFileFromSpec(array $value)
Create and return an UploadedFile instance from a $_FILES specification.
getQueryParams()
{Retrieve query string arguments.Retrieves the deserialized query string arguments, if any.Note: the query params might not be in sync with the URI or server params. If you need to ensure you are only getting the original values, you may need to parse the query string from getUri()->getQuery() or from the QUERY_STRING server param.array}
Representation of an incoming, server-side HTTP request.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
getServerParams()
{Retrieve server parameters.Retrieves data related to the incoming request environment, typically derived from PHP's $_SERVER superglobal. The data IS NOT REQUIRED to originate from $_SERVER.array}
static fromGlobals()
Return a ServerRequest populated with superglobals: $_GET $_POST $_COOKIE $_FILES $_SERVER...
Server-side HTTP request.
PSR-7 URI implementation.
withAttribute($attribute, $value)
{Return an instance with the specified derived request attribute.This method allows setting a single ...
getCookieParams()
{Retrieve cookies.Retrieves cookies sent by the client to the server.The data MUST be compatible with...
PSR-7 request implementation.
static normalizeNestedFileSpec(array $files=[])
Normalize an array of file specifications.
static normalizeFiles(array $files)
Return an UploadedFile instance array.
withCookieParams(array $cookies)
{Return an instance with the specified cookies.The data IS NOT REQUIRED to come from the $_COOKIE sup...
getAttributes()
{Retrieve attributes derived from the request.The request "attributes" may be used to allow injection...
withoutAttribute($attribute)
{Return an instance that removes the specified derived request attribute.This method allows removing ...
withParsedBody($data)
{Return an instance with the specified body parameters.These MAY be injected during instantiation...
Lazily reads or writes to a file that is opened only after an IO operation take place on the stream...
getParsedBody()
{Retrieve any parameters provided in the request body.If the request Content-Type is either applicati...
withQueryParams(array $query)
{Return an instance with the specified query string arguments.These values SHOULD remain immutable ov...
getAttribute($attribute, $default=null)
{Retrieve a single derived request attribute.Retrieves a single derived request attribute as describe...
getUploadedFiles()
{Retrieve normalized file upload data.This method returns upload metadata in a normalized tree...
static getUriFromGlobals()
Get a Uri populated with values from $_SERVER.
Value object representing a file uploaded through an HTTP request.
withUploadedFiles(array $uploadedFiles)
{Create a new instance with the specified uploaded files.This method MUST be implemented in such a wa...