PHP Class Neos\Flow\Http\Response

Inheritance: extends AbstractMessage, implements Neos\Flow\Mvc\ResponseInterface
Show file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$now DateTime The current point in time, used for comparisons
$parentResponse Response
$statusCode integer The HTTP status code
$statusMessage string The HTTP status message

Public Methods

Method Description
__construct ( Response $parentResponse = null ) Construct this Response
__toString ( ) : string Cast the response to a string: return the content part of this response
appendContent ( string $content ) : Response Appends content to the already existing content.
createFromRaw ( string $rawResponse, Response $parentResponse = null ) : Response Creates a response from the given raw, that is plain text, HTTP response.
getAge ( ) : integer Returns the age of this responds in seconds.
getContent ( ) : string Returns the response content without sending it.
getDate ( ) : DateTime Returns the date from the Date header.
getExpires ( ) : DateTime Returns the date from the Expires header or NULL if no such header is present.
getLastModified ( ) : DateTime Returns the date from the Last-Modified header or NULL if no such header is present.
getMaximumAge ( ) : integer Returns the maximum age in seconds before this response becomes stale.
getParentResponse ( ) : Response Return the parent response or NULL if none exists.
getSharedMaximumAge ( ) : integer Returns the maximum age in seconds before this response becomes stale in shared caches, such as proxies.
getStartLine ( ) : string Returns the first line of this Response Message, which is the Status-Line in this case
getStatus ( ) : string Returns status code and status message.
getStatusCode ( ) : integer Returns the status code.
getStatusLine ( ) : string Return the Status-Line of this Response Message, consisting of the version, the status code and the reason phrase Would be, for example, "HTTP/1.1 200 OK" or "HTTP/1.1 400 Bad Request"
getStatusMessageByCode ( integer $statusCode ) : string Returns the human-readable message for the given status code.
makeStandardsCompliant ( Request $request ) : void Analyzes this response, considering the given request and makes additions or removes certain headers in order to make the response compliant to RFC 2616 and related standards.
renderHeaders ( ) : array Renders the HTTP headers - including the status header - of this response
send ( ) : void Renders and sends the whole web response
sendHeaders ( ) : void Sends the HTTP headers.
setDate ( string | DateTime $date ) : Response Sets the Date header.
setExpires ( string | DateTime $date ) : Response Sets the Expires header.
setHeaders ( Headers $headers ) : void Replaces all possibly existing HTTP headers with the ones specified
setLastModified ( string | DateTime $date ) : Response Sets the Last-Modified header.
setMaximumAge ( integer $age ) : Response Sets the maximum age in seconds before this response becomes stale.
setNow ( DateTime $now ) : void Sets the current point in time.
setPrivate ( ) : Response Sets the respective directive in the Cache-Control header.
setPublic ( ) : Response Sets the respective directive in the Cache-Control header.
setSharedMaximumAge ( integer $maximumAge ) : Response Sets the maximum age in seconds before this response becomes stale in shared caches, such as proxies.
setStatus ( integer $code, string $message = null ) : Response Sets the HTTP status code and (optionally) a customized message.

Method Details

__construct() public method

Construct this Response
public __construct ( Response $parentResponse = null )
$parentResponse Response

__toString() public method

Cast the response to a string: return the content part of this response
public __toString ( ) : string
return string The same as getContent(), an empty string if getContent() returns a value which can't be cast into a string

appendContent() public method

Appends content to the already existing content.
public appendContent ( string $content ) : Response
$content string More response content
return Response This response, for method chaining

createFromRaw() public static method

Creates a response from the given raw, that is plain text, HTTP response.
public static createFromRaw ( string $rawResponse, Response $parentResponse = null ) : Response
$rawResponse string
$parentResponse Response Parent response, if called recursively
return Response

getAge() public method

The age is determined either by an explicitly set Age header or by the difference between Date and "now". Note that, according to RFC 2616 / 13.2.3, the presence of an Age header implies that the response is not first-hand. You should therefore only explicitly set an Age header if this is the case.
public getAge ( ) : integer
return integer The age in seconds

getContent() public method

Returns the response content without sending it.
public getContent ( ) : string
return string The response content

getDate() public method

The returned date is configured to be in the GMT timezone.
public getDate ( ) : DateTime
return DateTime The date of this response

getExpires() public method

The returned date is configured to be in the GMT timezone.
public getExpires ( ) : DateTime
return DateTime The expiration date or NULL

getLastModified() public method

The returned date is configured to be in the GMT timezone.
public getLastModified ( ) : DateTime
return DateTime The last modification date or NULL

getMaximumAge() public method

This method returns the value from the "max-age" directive in the Cache-Control header.
public getMaximumAge ( ) : integer
return integer The maximum age in seconds, or NULL if none has been defined

getParentResponse() public method

Return the parent response or NULL if none exists.
public getParentResponse ( ) : Response
return Response the parent response, or NULL if none

getSharedMaximumAge() public method

This method returns the value from the "s-maxage" directive in the Cache-Control header.
public getSharedMaximumAge ( ) : integer
return integer The maximum age in seconds, or NULL if none has been defined

getStartLine() public method

Returns the first line of this Response Message, which is the Status-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 Status-Line of this Response

getStatus() public method

Returns status code and status message.
public getStatus ( ) : string
return string The status code and status message, eg. "404 Not Found"

getStatusCode() public method

Returns the status code.
public getStatusCode ( ) : integer
return integer The status code, eg. 404

getStatusLine() public method

Return the Status-Line of this Response Message, consisting of the version, the status code and the reason phrase Would be, for example, "HTTP/1.1 200 OK" or "HTTP/1.1 400 Bad Request"
See also: http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
public getStatusLine ( ) : string
return string

getStatusMessageByCode() public static method

Returns the human-readable message for the given status code.
public static getStatusMessageByCode ( integer $statusCode ) : string
$statusCode integer
return string

makeStandardsCompliant() public method

It is recommended to call this method before the response is sent and Flow does so by default in its built-in HTTP request handler.
public makeStandardsCompliant ( Request $request ) : void
$request Request The corresponding request
return void

renderHeaders() public method

Renders the HTTP headers - including the status header - of this response
public renderHeaders ( ) : array
return array The HTTP headers

send() public method

Renders and sends the whole web response
public send ( ) : void
return void

sendHeaders() public method

If headers have been sent previously, this method fails silently.
public sendHeaders ( ) : void
return void

setDate() public method

The given date must either be an RFC2822 parseable date string or a DateTime object. The timezone will be converted to GMT internally, but the point in time remains the same.
public setDate ( string | DateTime $date ) : Response
$date string | DateTime
return Response This response, for method chaining

setExpires() public method

The given date must either be an RFC2822 parseable date string or a DateTime object. The timezone will be converted to GMT internally, but the point in time remains the same. In order to signal that the response has already expired, the date should be set to the same date as the Date header (that is, $now). To communicate an infinite expiration time, the date should be set to one year in the future. Expiration times should not be more than one year in the future, according to RFC 2616 / 14.21
public setExpires ( string | DateTime $date ) : Response
$date string | DateTime
return Response This response, for method chaining

setHeaders() public method

Replaces all possibly existing HTTP headers with the ones specified
public setHeaders ( Headers $headers ) : void
$headers Headers
return void

setLastModified() public method

The given date must either be an RFC2822 parseable date string or a DateTime object. The timezone will be converted to GMT internally, but the point in time remains the same.
public setLastModified ( string | DateTime $date ) : Response
$date string | DateTime
return Response This response, for method chaining

setMaximumAge() public method

This method sets the "max-age" directive in the Cache-Control header.
public setMaximumAge ( integer $age ) : Response
$age integer The maximum age in seconds
return Response This response, for method chaining

setNow() public method

This date / time is used internally for comparisons in order to determine the freshness of this response. By default this DateTime object is set automatically through dependency injection, configured in the Objects.yaml of the Flow package. Unless you are mocking the current time in a test, there is probably no need to use this function. Also note that this method must be called before any of the Response methods are used and it must not be called a second time.
public setNow ( DateTime $now ) : void
$now DateTime The current point in time
return void

setPrivate() public method

A response flagged as "private" tells that it is intended for a specific user and must not be cached by a shared cache.
public setPrivate ( ) : Response
return Response This response, for method chaining

setPublic() public method

A response flagged as "public" may be cached by any cache, even if it normally wouldn't be cacheable in a shared cache.
public setPublic ( ) : Response
return Response This response, for method chaining

setSharedMaximumAge() public method

This method sets the "s-maxage" directive in the Cache-Control header.
public setSharedMaximumAge ( integer $maximumAge ) : Response
$maximumAge integer The maximum age in seconds
return Response This response, for method chaining

setStatus() public method

Sets the HTTP status code and (optionally) a customized message.
public setStatus ( integer $code, string $message = null ) : Response
$code integer The status code
$message string If specified, this message is sent instead of the standard message
return Response This response, for method chaining

Property Details

$now protected property

The current point in time, used for comparisons
protected DateTime $now
return DateTime

$parentResponse protected property

protected Response,Neos\Flow\Http $parentResponse
return Response

$statusCode protected property

The HTTP status code
protected int $statusCode
return integer

$statusMessage protected property

The HTTP status message
protected string $statusMessage
return string