Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
withUploadedFiles example
$parsedBody
=
json_decode
(
$symfonyRequest
->
getContent
(
)
, true, 512, \JSON_BIGINT_AS_STRING
)
;
if
(
!\
is_array
(
$parsedBody
)
)
{
$parsedBody
= null;
}
}
else
{
$parsedBody
=
$symfonyRequest
->request->
all
(
)
;
}
$request
=
$request
->
withBody
(
$body
)
->
withUploadedFiles
(
$this
->
getFiles
(
$symfonyRequest
->files->
all
(
)
)
)
->
withCookieParams
(
$symfonyRequest
->cookies->
all
(
)
)
->
withQueryParams
(
$symfonyRequest
->query->
all
(
)
)
->
withParsedBody
(
$parsedBody
)
;
foreach
(
$symfonyRequest
->attributes->
all
(
)
as
$key
=>
$value
)
{
$request
=
$request
->
withAttribute
(
$key
,
$value
)
;
}
return
$request
;
}
$new
=
(
new
ServerRequest
(
$changes
[
'method'
]
??
$request
->
getMethod
(
)
,
$uri
,
$headers
,
$changes
[
'body'
]
??
$request
->
getBody
(
)
,
$changes
[
'version'
]
??
$request
->
getProtocolVersion
(
)
,
$request
->
getServerParams
(
)
)
)
->
withParsedBody
(
$request
->
getParsedBody
(
)
)
->
withQueryParams
(
$request
->
getQueryParams
(
)
)
->
withCookieParams
(
$request
->
getCookieParams
(
)
)
->
withUploadedFiles
(
$request
->
getUploadedFiles
(
)
)
;
foreach
(
$request
->
getAttributes
(
)
as
$key
=>
$value
)
{
$new
=
$new
->
withAttribute
(
$key
,
$value
)
;
}
return
$new
;
}
return
new
Request
(
$changes
[
'method'
]
??
$request
->
getMethod
(
)
,
$uri
,
try
{
$request
=
$request
->
withHeader
(
$name
,
$value
)
;
}
catch
(
\InvalidArgumentException
$e
)
{
// ignore invalid header
}
}
$body
=
$this
->streamFactory->
createStreamFromResource
(
$symfonyRequest
->
getContent
(
true
)
)
;
$request
=
$request
->
withBody
(
$body
)
->
withUploadedFiles
(
$this
->
getFiles
(
$symfonyRequest
->files->
all
(
)
)
)
->
withCookieParams
(
$symfonyRequest
->cookies->
all
(
)
)
->
withQueryParams
(
$symfonyRequest
->query->
all
(
)
)
->
withParsedBody
(
$symfonyRequest
->request->
all
(
)
)
;
foreach
(
$symfonyRequest
->attributes->
all
(
)
as
$key
=>
$value
)
{
$request
=
$request
->
withAttribute
(
$key
,
$value
)
;
}
return
$request
;
}
$headers
=
getallheaders
(
)
;
$uri
= self::
getUriFromGlobals
(
)
;
$body
=
new
CachingStream
(
new
LazyOpenStream
(
'php://input', 'r+'
)
)
;
$protocol
=
isset
(
$_SERVER
[
'SERVER_PROTOCOL'
]
)
?
str_replace
(
'HTTP/', '',
$_SERVER
[
'SERVER_PROTOCOL'
]
)
: '1.1';
$serverRequest
=
new
ServerRequest
(
$method
,
$uri
,
$headers
,
$body
,
$protocol
,
$_SERVER
)
;
return
$serverRequest
->
withCookieParams
(
$_COOKIE
)
->
withQueryParams
(
$_GET
)
->
withParsedBody
(
$_POST
)
->
withUploadedFiles
(
self::
normalizeFiles
(
$_FILES
)
)
;
}
private
static
function
extractHostAndPortFromAuthority
(
string
$authority
)
: array
{
$uri
= 'http://'.
$authority
;
$parts
=
parse_url
(
$uri
)
;
if
(
false ===
$parts
)
{
return
[
null, null
]
;
}
$host
=
$parts
[
'host'
]
?? null;