PHP Class Phly\Http\ServerRequestFactory

Logic largely refactored from the ZF2 Zend\Http\PhpEnvironment\Request class.
Datei anzeigen Open project: phly/http Class Usage Examples

Public Methods

Method Description
fromGlobals ( array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null ) : ServerRequest Create a request from the supplied superglobal values.
get ( string $key, array $values, mixed $default = null ) : mixed Access a value in an array, returning a default value if not found
getHeader ( string $header, array $headers, mixed $default = null ) : string Search for a header value.
marshalHeaders ( array $server ) : array Marshal headers from $_SERVER
marshalHostAndPort ( stdClass $accumulator, array $server, Psr\Http\Message\MessageInterface $request ) : array Marshal the host and port from HTTP headers and/or the PHP environment
marshalHostAndPortFromHeaders ( stdClass $accumulator, array $server, array $headers ) : array Marshal the host and port from HTTP headers and/or the PHP environment
marshalRequestUri ( array $server ) : string Detect the base URI for the request
marshalUri ( array $server, Psr\Http\Message\MessageInterface $request ) : Uri Marshal the URI from the $_SERVER array and headers
marshalUriFromServer ( array $server, array $headers ) : Uri Marshal the URI from the $_SERVER array and headers
normalizeFiles ( array $files ) : array Normalize uploaded files
normalizeServer ( array $server ) : array Marshal the $_SERVER array
stripQueryString ( mixed $path ) : void Strip the query string from a path

Private Methods

Method Description
createUploadedFileFromSpec ( array $value ) : array | Psr\Http\Message\UploadedFileInterface Create and return an UploadedFile instance from a $_FILES specification.
marshalHostAndPortFromHeader ( stdClass $accumulator, string | array $host ) : void Marshal the host and port from the request header
marshalIpv6HostAndPort ( stdClass $accumulator, array $server ) Marshal host/port from misinterpreted IPv6 address
normalizeNestedFileSpec ( array $files ) : Psr\Http\Message\UploadedFileInterface[] Normalize an array of file specifications.

Method Details

fromGlobals() public static method

If any argument is not supplied, the corresponding superglobal value will be used. The ServerRequest created is then passed to the fromServer() method in order to marshal the request URI and headers.
See also: fromServer()
public static fromGlobals ( array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null ) : ServerRequest
$server array $_SERVER superglobal
$query array $_GET superglobal
$body array $_POST superglobal
$cookies array $_COOKIE superglobal
$files array $_FILES superglobal
return ServerRequest

get() public static method

Will also do a case-insensitive search if a case sensitive search fails.
public static get ( string $key, array $values, mixed $default = null ) : mixed
$key string
$values array
$default mixed
return mixed

getHeader() public static method

Does a case-insensitive search for a matching header. If found, it is returned as a string, using comma concatenation. If not, the $default is returned.
public static getHeader ( string $header, array $headers, mixed $default = null ) : string
$header string
$headers array
$default mixed
return string

marshalHeaders() public static method

Marshal headers from $_SERVER
public static marshalHeaders ( array $server ) : array
$server array
return array

marshalHostAndPort() public static method

Marshal the host and port from HTTP headers and/or the PHP environment
Deprecation: as of 0.7.0; use marshalHostAndPortFromHeaders() instead.
public static marshalHostAndPort ( stdClass $accumulator, array $server, Psr\Http\Message\MessageInterface $request ) : array
$accumulator stdClass
$server array
$request Psr\Http\Message\MessageInterface
return array Array with two members, host and port, at indices 0 and 1, respectively

marshalHostAndPortFromHeaders() public static method

Marshal the host and port from HTTP headers and/or the PHP environment
public static marshalHostAndPortFromHeaders ( stdClass $accumulator, array $server, array $headers ) : array
$accumulator stdClass
$server array
$headers array
return array Array with two members, host and port, at indices 0 and 1, respectively

marshalRequestUri() public static method

Looks at a variety of criteria in order to attempt to autodetect a base URI, including rewrite URIs, proxy URIs, etc. From ZF2's Zend\Http\PhpEnvironment\Request class
public static marshalRequestUri ( array $server ) : string
$server array
return string

marshalUri() public static method

Marshal the URI from the $_SERVER array and headers
Deprecation: as of 0.7.0; use marshalUriFromServer() instead.
public static marshalUri ( array $server, Psr\Http\Message\MessageInterface $request ) : Uri
$server array
$request Psr\Http\Message\MessageInterface
return Uri

marshalUriFromServer() public static method

Marshal the URI from the $_SERVER array and headers
public static marshalUriFromServer ( array $server, array $headers ) : Uri
$server array
$headers array
return Uri

normalizeFiles() public static method

Transforms each value into an UploadedFileInterface instance, and ensures that nested arrays are normalized.
public static normalizeFiles ( array $files ) : array
$files array
return array

normalizeServer() public static method

Pre-processes and returns the $_SERVER superglobal.
public static normalizeServer ( array $server ) : array
$server array
return array

stripQueryString() public static method

Strip the query string from a path
public static stripQueryString ( mixed $path ) : void
$path mixed
return void