Closed weierophinney closed 6 years ago
Outstanding questions:
FromSapi()
suffix, while others do not. Add it to those that do not, or remove it from those that do?normalize
with two functions that aggregate UploadedFileInterface
instances; would it be better to use the marshal
prefix as I do elsewhere?A function suggestion.
https://github.com/zendframework/zend-diactoros/blob/1.7.2/src/ServerRequestFactory.php#L393-L399
public static function stripQueryString($path)
{
if (($qpos = strpos($path, '?')) !== false) {
return substr($path, 0, $qpos);
}
return $path;
}
There can be simpler code.
public static function stripQueryString($path)
{
return explode('?', $path, 2)[0];
}
Thanks, @Moln ; incorporated both in that method, as well as the inlined version in marshalUriFromSapi()
.
I've made the following changes at this time:
Zend\Diactoros\marshalUriFromSapi()
function; this allowed removing each of getHeaderFromArray()
, marshalHostandPort()
, and marshalIpv6HostAndPort()
.Zend\Diactoros\marshalProtocolVersionFromSapi()
.Zend\Diactoros\marshalMethodFromSapi(array $server) : string
.Zend\Diactoros\normalizeUploadedFiles()
; createUploadedFile()
was kept, as it has standalone use cases.I've also updated ServerRequestFactory
to follow all changes.
At this point, I think this is ready for final review.
This patch serves as an alternative to #306. It extracts a number of methods from
ServerRequestFactory
into dedicated functions, allowing them to be used to deriveServerRequest
artifacts.tl;dr: This patch removes all
private
methods ofServerRequestFactory
, and adds the following functions under theZend\Diactoros
namespace:normalizeServer(array $server, callable $apacheRequestHeaderCallback = null) : array
(main purpose is to aggregate theAuthorization
header in the SAPI params when under Apache)marshalProtocolVersionFromSapi(array $server) : string
marshalMethodFromSapi(array $server) : string
marshalUriFromSapi(array $server, array $headers) : Uri
marshalHeadersFromSapi(array $server) : array
parseCookieHeader(string $header) : array
createUploadedFile(array $spec) : UploadedFile
(creates the instance from a normal$_FILES
entry)normalizeUploadedFiles(array $files) : UploadedFileInterface[]
(traverses a potentially nested array of uploaded file instances and/or$_FILES
entries, including those aggregated under mod_php, php-fpm, and php-cgi in order to create a flat array ofUploadedFileInterface
instances to use in a request)The full set of changes include:
$_SERVER
normalization:Zend\Diactoros\normalizeServer(array $server, callable $apacheRequestHeaderCallback = null) : array)
for preparing the SAPI params to include theAuthorization
header; this is mainly done to ensure it is extracted properly under Apache.ServerRequestFactory::normalizeServer()
, and has it proxy tonormalizeServer()
; it is no longer used internally.Zend\Diactoros\marshalHeadersFromSapi(array $server) : array
for marshaling HTTP request headers from the SAPI$_SERVER
array.ServerRequestFactory::marshalHeaders()
, and has it proxy tomarshalHeadersFromSapi()
; the method is no longer used internally.Zend\Diactoros\marshalProtocolVersionFromSapi(array $server) : string
ServerRequestFactory::marshalProtocolVersion()
Zend\Diactoros\marshalMethodFromSapi(array $server) : string
Zend\Diactoros\marshalUriFromSapi(array $server, array $headers) : Uri
for marshaling aUri
instance from the SAPI parameters and/or HTTP request headers. The function inlines the logic from each ofServerRequestFactory::getHeader()
,ServerRequestFactory::marshalHostAndPortFromHeaders()
,ServerRequestFactory::marshalHostAndPortFromHeader()
,ServerRequestFactory::marshalRequestUri()
,ServerRequestFactory::marshalUrifromServer()
, andServerRequestFactory::stripQueryString()
.ServerRequestFactory::getHeader()
, and has it proxy togetHeaderFromArray()
.ServerRequestFactory::marshalHostAndPortFromHeaders()
, and has it proxy to `marshalHostAndPort(). It is no longer used internally.ServerRequestFactory::marshalRequestUri()
, and has it proxy tomarshalRequestPath()
. The method is no longer used internally.ServerRequestFactory::marshalUriFromServer()
, and has it proxy tomarshalUriFromSapi()
The method is no longer used internally.ServerRequestFactory::stripQueryString()
. The method is no longer used internally.ServerRequestFactory::marshalHostAndPortFromHeader()
ServerRequestFactory::marshalIpv6HostAndPort()
Zend\Diactoros\parseCookieHeader(string $cookieHeader) : array
ServerRequestFactory::parseCookieHeader()
Zend\Diactoros\createUploadedFile(array $spec) : UploadedFile
Zend\Diactoros\normalizeUploadedFiles(array $files) : UploadedFileInterface[]
ServerRequestFactory::createUploadedFileFromSpec()
(was private previously; logic now increateUploadedFile()
)ServerRequestFactory::normalizeNestedFileSpec()
(was private previously; logic now incorporated innormalizeUploadedFiles()
)ServerRequestFactory::normalizeFiles()
; the method is no longer used internally, and now proxies tonormalizeUploadedFiles()
.