PHP Class Neos\Flow\Http\Request

Inheritance: extends AbstractMessage
ファイルを表示 Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$arguments array
$attributes array PSR-7
$baseUri Uri
$inputStreamUri string URI for the "input" stream wrapper which can be modified for testing purposes
$method string
$server array Data similar to that which is typically provided by $_SERVER
$uri Uri

Public Methods

Method Description
__clone ( ) Creates a deep clone
__construct ( array $get, array $post, array $files, array $server ) Constructs a new Request object based on the given environment data.
__toString ( ) : string Cast the request to a string: return the content part of this response
create ( Uri $uri, string $method = 'GET', array $arguments = [], array $files = [], array $server = [] ) : Request Creates a new Request object from the given data.
createActionRequest ( ) : ActionRequest Creates a new Action Request request as a sub request to this HTTP request.
createFromEnvironment ( ) : Request Considers the environment information found in PHP's superglobals and Flow's environment configuration and creates a new instance of this Request class matching that data.
getAcceptedMediaTypes ( ) : array Returns an list of IANA media types defined in the Accept header.
getArgument ( string $name ) : mixed Returns the value of the specified GET / POST / PUT argument.
getArguments ( ) : array Returns the unified arguments of this request.
getAttribute ( string $name, mixed $default = null ) : mixed PSR-7
getAttributes ( ) : mixed[] PSR-7
getBaseUri ( ) : Uri Returns the detected base URI
getClientIpAddress ( ) : string Returns the best guess of the client's IP address.
getContent ( boolean $asResource = false ) : string | resource Returns the content of the request body
getMethod ( ) : string Returns the request method
getNegotiatedMediaType ( array $supportedMediaTypes, boolean $trim = true ) : string Returns the best fitting IANA media type after applying the content negotiation rules on a possible Accept header.
getPort ( ) : integer Returns the port used for this request
getRelativePath ( ) : string Returns the request's path relative to the $baseUri
getRequestLine ( ) : string Return the Request-Line of this Request Message, consisting of the method, the uri and the HTTP version Would be, for example, "GET /foo?bar=baz HTTP/1.1" Note that the URI part is, at the moment, only possible in the form "abs_path" since the actual requestUri of the Request cannot be determined during the creation of the Request.
getScriptRequestPath ( ) : string Returns the relative path (ie. relative to the web root) to the script as it was accessed through the web server.
getScriptRequestPathAndFilename ( ) : string Returns the relative path (ie. relative to the web root) and name of the script as it was accessed through the web server.
getServerParams ( ) : array PSR-7
getStartLine ( ) : string Returns the first line of this Request Message, which is the Request-Line in this case
getUri ( ) : Uri Returns the request URI
hasArgument ( string $name ) : boolean Checks if an argument of the given name exists in this request.
isMethodSafe ( ) : boolean Tells if the request method is "safe", that is, it is expected to not take any other action than retrieval. This should the case with "GET" and "HEAD" requests.
isSecure ( ) : boolean Indicates if this request has been received through a secure channel.
mediaRangeMatches ( string $mediaRange, string $mediaType ) : boolean Checks if the given media range and the media type match.
parseContentNegotiationQualityValues ( string $rawValues ) : array Parses a RFC 2616 content negotiation header field by evaluating the Quality Values and splitting the options into an array list, ordered by user preference.
parseMediaType ( string $rawMediaType ) : array Parses a RFC 2616 Media Type and returns its parts in an associative array.
renderHeaders ( ) : string Renders the HTTP headers - including the status header - of this request
setBaseUri ( Uri $baseUri )
setContent ( string | resource $content ) : void Explicitly sets the content of the request body
setMethod ( string $method ) : void Sets the request method
trimMediaType ( string $rawMediaType ) : string Strips off any parameters from the given media type and returns just the type and subtype in the format "type/subtype".
withAttribute ( string $name, mixed $value ) : self PSR-7
withoutAttribute ( string $name ) : self PSR-7

Protected Methods

Method Description
buildUnifiedArguments ( array $getArguments, array $postArguments, array $uploadArguments ) : array Takes the raw GET & POST arguments and maps them into the request object.
calculateFieldPaths ( array $structure, string $firstLevelFieldName = null ) : array Returns and array of all possibles "field paths" for the given array.
detectBaseUri ( ) : void Tries to detect the base URI of request.
setAttribute ( string $name, mixed $value )
unsetAttribute ( string $name )
untangleFilesArray ( array $convolutedFiles ) : array Transforms the convoluted _FILES superglobal into a manageable form.

Method Details

__clone() public method

Creates a deep clone
public __clone ( )

__construct() public method

Constructs a new Request object based on the given environment data.
See also: create()
See also: createFromEnvironment()
public __construct ( array $get, array $post, array $files, array $server )
$get array Data similar to that which is typically provided by $_GET
$post array Data similar to that which is typically provided by $_POST
$files array Data similar to that which is typically provided by $_FILES
$server array Data similar to that which is typically provided by $_SERVER

__toString() public method

Cast the request to a string: return the content part of this response
public __toString ( ) : string
return string The same as getContent()

buildUnifiedArguments() protected method

Afterwards all mapped arguments can be retrieved by the getArgument(s) method, no matter if they have been GET, POST or PUT arguments before.
protected buildUnifiedArguments ( array $getArguments, array $postArguments, array $uploadArguments ) : array
$getArguments array Arguments as found in $_GET
$postArguments array Arguments as found in $_POST
$uploadArguments array Arguments as found in $_FILES
return array the unified arguments

calculateFieldPaths() protected method

Returns and array of all possibles "field paths" for the given array.
protected calculateFieldPaths ( array $structure, string $firstLevelFieldName = null ) : array
$structure array The array to walk through
$firstLevelFieldName string
return array An array of paths (as strings) in the format "key1/key2/key3" ...

create() public static method

Creates a new Request object from the given data.
public static create ( Uri $uri, string $method = 'GET', array $arguments = [], array $files = [], array $server = [] ) : Request
$uri Uri The request URI
$method string Request method, for example "GET"
$arguments array Arguments to send in the request body
$files array
$server array
return Request

createActionRequest() public method

Maps the arguments of this request to the new Action Request.
Deprecation: since Flow 2.3. Create the ActionRequest manually instead: $actionRequest = new ActionRequest($httpRequest)
public createActionRequest ( ) : ActionRequest
return Neos\Flow\Mvc\ActionRequest

createFromEnvironment() public static method

Considers the environment information found in PHP's superglobals and Flow's environment configuration and creates a new instance of this Request class matching that data.
public static createFromEnvironment ( ) : Request
return Request

detectBaseUri() protected method

Tries to detect the base URI of request.
protected detectBaseUri ( ) : void
return void

getAcceptedMediaTypes() public method

The list is ordered by user preference, after evaluating the Quality Values specified in the header field value. First items in the list are the most preferred. If no Accept header is present, the media type representing "any" media type is returned.
public getAcceptedMediaTypes ( ) : array
return array A list of media types and sub types

getArgument() public method

Returns the value of the specified GET / POST / PUT argument.
public getArgument ( string $name ) : mixed
$name string Name of the argument
return mixed Value of the specified argument or NULL if it does not exist

getArguments() public method

GET, POST and PUT arguments, as well es uploaded files, are merged into a whole array of arguments.
public getArguments ( ) : array
return array

getAttribute() public method

Retrieve a single derived request attribute. Retrieves a single derived request attribute as described in getAttributes(). If the attribute has not been previously set, returns the default value as provided. This method obviates the need for a hasAttribute() method, as it allows specifying a default value to return if the attribute is not found.
See also: getAttributes()
public getAttribute ( string $name, mixed $default = null ) : mixed
$name string The attribute name.
$default mixed Default value to return if the attribute does not exist.
return mixed

getAttributes() public method

Retrieve attributes derived from the request. The request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.
public getAttributes ( ) : mixed[]
return mixed[] Attributes derived from the request.

getBaseUri() public method

Returns the detected base URI
public getBaseUri ( ) : Uri
return Uri

getClientIpAddress() public method

Note that, depending on the actual source used, IP addresses can be spoofed and may not be reliable. Although several kinds of proxy headers are taken into account, certain combinations of ISPs and proxies might still produce wrong results. Don't rely on the client IP address as the only security measure!
public getClientIpAddress ( ) : string
return string The client's IP address

getContent() public method

If the request body has not been set with setContent() previously, this method will try to retrieve it from the input stream. If $asResource was set to TRUE, the stream resource will be returned instead of a string. If the content which has been set by setContent() originally was a stream resource, that resource will be returned, no matter if $asResource is set.
public getContent ( boolean $asResource = false ) : string | resource
$asResource boolean If set, the content is returned as a resource pointing to PHP's input stream
return string | resource

getMethod() public method

Returns the request method
public getMethod ( ) : string
return string The request method

getNegotiatedMediaType() public method

Returns the best fitting IANA media type after applying the content negotiation rules on a possible Accept header.
public getNegotiatedMediaType ( array $supportedMediaTypes, boolean $trim = true ) : string
$supportedMediaTypes array A list of media types which are supported by the application / controller
$trim boolean If TRUE, only the type/subtype of the media type is returned. If FALSE, the full original media type string is returned.
return string The media type and sub type which matched, NULL if none matched

getPort() public method

Returns the port used for this request
public getPort ( ) : integer
return integer

getRelativePath() public method

Returns the request's path relative to the $baseUri
public getRelativePath ( ) : string
return string

getRequestLine() public method

Return the Request-Line of this Request Message, consisting of the method, the uri and the HTTP version Would be, for example, "GET /foo?bar=baz HTTP/1.1" Note that the URI part is, at the moment, only possible in the form "abs_path" since the actual requestUri of the Request cannot be determined during the creation of the Request.
See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1
public getRequestLine ( ) : string
return string

getScriptRequestPath() public method

Returns the relative path (ie. relative to the web root) to the script as it was accessed through the web server.
public getScriptRequestPath ( ) : string
return string Relative path to the PHP script as accessed through the web

getScriptRequestPathAndFilename() public method

Returns the relative path (ie. relative to the web root) and name of the script as it was accessed through the web server.
public getScriptRequestPathAndFilename ( ) : string
return string Relative path and name of the PHP script as accessed through the web

getServerParams() public method

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.
public getServerParams ( ) : array
return array

getStartLine() public method

Returns the first line of this Request Message, which is the Request-Line in this case
See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html chapter 4.1 "Message Types"
public getStartLine ( ) : string
return string The Request-Line of this Request

getUri() public method

Returns the request URI
public getUri ( ) : Uri
return Uri

hasArgument() public method

Applies to GET, POST and PUT arguments similarly.
public hasArgument ( string $name ) : boolean
$name string Name of the argument
return boolean

isMethodSafe() public method

Tells if the request method is "safe", that is, it is expected to not take any other action than retrieval. This should the case with "GET" and "HEAD" requests.
public isMethodSafe ( ) : boolean
return boolean

isSecure() public method

Indicates if this request has been received through a secure channel.
public isSecure ( ) : boolean
return boolean

mediaRangeMatches() public static method

Checks if the given media range and the media type match.
See also: MediaTypes::mediaRangeMatches()
Deprecation: since Flow 2.1. Use \Neos\Utility\MediaTypes::mediaRangeMatches() instead
public static mediaRangeMatches ( string $mediaRange, string $mediaType ) : boolean
$mediaRange string The media range, for example "text/*"
$mediaType string The media type to match against, for example "text/html"
return boolean TRUE if both match, FALSE if they don't match or either of them is invalid

parseContentNegotiationQualityValues() public static method

Parses a RFC 2616 content negotiation header field by evaluating the Quality Values and splitting the options into an array list, ordered by user preference.
public static parseContentNegotiationQualityValues ( string $rawValues ) : array
$rawValues string The raw Accept* Header field value
return array The parsed list of field values, ordered by user preference

parseMediaType() public static method

Parses a RFC 2616 Media Type and returns its parts in an associative array.
See also: MediaTypes::parseMediaType()
Deprecation: since Flow 2.1. Use \Neos\Utility\MediaTypes::parseMediaType() instead
public static parseMediaType ( string $rawMediaType ) : array
$rawMediaType string The raw media type, for example "application/json; charset=UTF-8"
return array An associative array with parsed information

renderHeaders() public method

Renders the HTTP headers - including the status header - of this request
public renderHeaders ( ) : string
return string The HTTP headers, one per line, separated by \r\n as required by RFC 2616 sec 5

setAttribute() protected method

protected setAttribute ( string $name, mixed $value )
$name string The attribute name.
$value mixed The value of the attribute.

setBaseUri() public method

public setBaseUri ( Uri $baseUri )
$baseUri Uri

setContent() public method

In most cases, content is just a string representation of the request body. In order to reduce memory consumption for uploads and other big data, it is also possible to pass a stream resource. The easies way to convert a local file into a stream resource is probably: $resource = fopen('file://path/to/file', 'rb');
public setContent ( string | resource $content ) : void
$content string | resource The body content, for example arguments of a PUT request, or a stream resource
return void

setMethod() public method

Sets the request method
public setMethod ( string $method ) : void
$method string The request method, for example "GET".
return void

trimMediaType() public static method

Strips off any parameters from the given media type and returns just the type and subtype in the format "type/subtype".
See also: Neos\Utility\MediaTypes::trimMediaType()
Deprecation: since Flow 2.1. Use \Neos\Utility\MediaTypes::trimMediaType() instead
public static trimMediaType ( string $rawMediaType ) : string
$rawMediaType string The full media type, for example "application/json; charset=UTF-8"
return string Just the type and subtype, for example "application/json"

unsetAttribute() protected method

protected unsetAttribute ( string $name )
$name string The attribute name.

untangleFilesArray() protected method

Transforms the convoluted _FILES superglobal into a manageable form.
protected untangleFilesArray ( array $convolutedFiles ) : array
$convolutedFiles array The _FILES superglobal
return array Untangled files

withAttribute() public method

Return an instance with the specified derived request attribute. This method allows setting a single derived request attribute as described in getAttributes(). This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated attribute.
See also: getAttributes()
public withAttribute ( string $name, mixed $value ) : self
$name string The attribute name.
$value mixed The value of the attribute.
return self

withoutAttribute() public method

Return an instance that removes the specified derived request attribute. This method allows removing a single derived request attribute as described in getAttributes(). This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the attribute.
See also: getAttributes()
public withoutAttribute ( string $name ) : self
$name string The attribute name.
return self

Property Details

$arguments protected_oe property

protected array $arguments
return array

$attributes protected_oe property

PSR-7
protected array $attributes
return array

$baseUri protected_oe property

protected Uri,Neos\Flow\Http $baseUri
return Uri

$inputStreamUri protected_oe property

URI for the "input" stream wrapper which can be modified for testing purposes
protected string $inputStreamUri
return string

$method protected_oe property

protected string $method
return string

$server protected_oe property

Data similar to that which is typically provided by $_SERVER
protected array $server
return array

$uri protected_oe property

protected Uri,Neos\Flow\Http $uri
return Uri