Overview
  • Namespace
  • Class
  • Tree

Namespaces

  • Modulework
    • Modules
      • Http
        • Exceptions
        • Utilities
  • PHP

Classes

  • Cookie
  • JsonResponse
  • RedirectResponse
  • Request
  • Response

Class Response

Response This class should represent the HTTP response, done by the application.

Direct known subclasses

Modulework\Modules\Http\JsonResponse, Modulework\Modules\Http\RedirectResponse

Namespace: Modulework\Modules\Http
Located at Modulework/Modules/Http/Response.php

Methods summary

public static Modulework\Modules\Http\Response
# make( string $content = '', integer $code = 200, array $headers = array(), Modulework\Modules\Http\Utilities\HeaderWrapperInterface $headerWrapper = null )

Factory for the Response object

Factory for the Response object

Parameters

$content
string
$content The body of the HTTP response
$code
integer
$code The HTTP status code
$headers
array
$headers The HTTP headers
$headerWrapper
Modulework\Modules\Http\Utilities\HeaderWrapperInterface
| null $headerWrapper The wrapper for PHP' s native header releated functions

Returns

Modulework\Modules\Http\Response
The new Response object

Throws

InvalidArgumentException
(from Constructor)
public static Modulework\Modules\Http\Response
# fromException( Modulework\Modules\Http\Exceptions\HttpExceptionInterface $e, array $headers = array(), Modulework\Modules\Http\Utilities\HeaderWrapperInterface $headerWrapper = null )

Factory for the Response object Create a Response from a HttpException

Factory for the Response object Create a Response from a HttpException

Parameters

$e
Modulework\Modules\Http\Exceptions\HttpExceptionInterface
$e The exception
$headers
array
$headers The HTTP headers
$headerWrapper
Modulework\Modules\Http\Utilities\HeaderWrapperInterface
| null $headerWrapper The wrapper for PHP' s native header releated functions

Returns

Modulework\Modules\Http\Response
The new Response object

Throws

InvalidArgumentException
(from Constructor)
public Modulework\Modules\Http\Response
# __construct( string $content = '', integer $code = 200, array $headers = array(), Modulework\Modules\Http\Utilities\HeaderWrapperInterface $headerWrapper = null )

Constructor.

Constructor.

Parameters

$content
string
$content The body of the HTTP response
$code
integer
$code The HTTP status code
$headers
array
$headers The HTTP headers
$headerWrapper
Modulework\Modules\Http\Utilities\HeaderWrapperInterface
| null $headerWrapper The wrapper for PHP' s native header releated functions

Returns

Modulework\Modules\Http\Response
The new Response object

Throws

InvalidArgumentException
(from setContent)
public string
# __toString( )

PHP' s magic method __toString Format: HTTP/{VERSION} {STATUSCODE} {STATUSTEXT} {HEADERS} {BODY}

PHP' s magic method __toString Format: HTTP/{VERSION} {STATUSCODE} {STATUSTEXT} {HEADERS} {BODY}

Returns

string
The response as string
public Modulework\Modules\Http\Utilities\HeaderWrapperInterface
# setHeaderWrapper( Modulework\Modules\Http\Utilities\HeaderWrapperInterface $headerWrapper = null )

Dependency injection for the HeaderWrapper (also availbe thru the constructor) If null is passed it will create a new instance of \Modulework\Modules\Http\Utilities\HeaderWrapper

Dependency injection for the HeaderWrapper (also availbe thru the constructor) If null is passed it will create a new instance of \Modulework\Modules\Http\Utilities\HeaderWrapper

It returns the "previous" HeaderWrapper or null

Parameters

$headerWrapper
Modulework\Modules\Http\Utilities\HeaderWrapperInterface
$headerWrapper The HeaderWrapper

Returns

Modulework\Modules\Http\Utilities\HeaderWrapperInterface
| null "previous" HeaderWrapper | null
public Modulework\Modules\Http\Response
# sendHeaders( )

Send the headers and cookies to the client

Send the headers and cookies to the client

Returns

Modulework\Modules\Http\Response
THIS

Uses

Modulework\Modules\Http\Response::sendCookies()

Used by

Modulework\Modules\Http\Response::send()
public Modulework\Modules\Http\Response
# sendCookies( )

Send the cookies only to the client

Send the cookies only to the client

Returns

Modulework\Modules\Http\Response
THIS

Used by

Modulework\Modules\Http\Response::sendHeaders()
public Modulework\Modules\Http\Response
# sendContent( )

Sends the content to the client

Sends the content to the client

Returns

Modulework\Modules\Http\Response
THIS

Used by

Modulework\Modules\Http\Response::send()
public Modulework\Modules\Http\Response
# send( )

Send the response to the client (headers, cookies, content)

Send the response to the client (headers, cookies, content)

Returns

Modulework\Modules\Http\Response
THIS

Uses

Modulework\Modules\Http\Response::sendHeaders()
Modulework\Modules\Http\Response::sendContent()
public Modulework\Modules\Http\Response
# prepare( Modulework\Modules\Http\Request $request )

Prepares the response based on the Request object This method is not essential and can be cut out of the chain. However it cleans up the headers and does some other stuff under the hood.

Prepares the response based on the Request object This method is not essential and can be cut out of the chain. However it cleans up the headers and does some other stuff under the hood.

Parameters

$request
Modulework\Modules\Http\Request
$req The request object

Returns

Modulework\Modules\Http\Response
THIS
public
# addCookie( Modulework\Modules\Http\Cookie $cookie )

Add a cookie to the response

Add a cookie to the response

Parameters

$cookie
Modulework\Modules\Http\Cookie
$cookie The cookie object
public
# addHeader( string $name, string $value, boolean $overwrite = false )

Add a header to the response

Add a header to the response

Parameters

$name
string
$name The name of the header (e.g. "Location")
$value
string
$value The value of the header (e.g. "foo.bar")
$overwrite
boolean
$overwrite Whether it should replaces existing headers
public Modulework\Modules\Http\Response
# setStatusCode( integer $code = 200, string $txt = null )

Set the status code of the response If the text is null it will try to determine the text from the internal lib

Set the status code of the response If the text is null it will try to determine the text from the internal lib

Parameters

$code
integer
$code The status code
$txt
string
$txt The status text

Returns

Modulework\Modules\Http\Response
THIS
public integer
# getStatusCode( )

Returns the status code of this response

Returns the status code of this response

Returns

integer
The status code
public Modulework\Modules\Http\Response
# setContent( string $content = '' )

Set the content for this response

Set the content for this response

Parameters

$content
string
$content The content

Returns

Modulework\Modules\Http\Response
THIS

Throws

InvalidArgumentException
public Modulework\Modules\Http\Response
# appendContent( string $content = '' )

Append to the content for this response

Append to the content for this response

Parameters

$content
string
$content The content to append

Returns

Modulework\Modules\Http\Response
THIS

Throws

InvalidArgumentException
public string
# getContent( )

Returns the content of this response

Returns the content of this response

Returns

string
The content
public Modulework\Modules\Http\Response
# setDate( DateTime $date )

Set the date for this request

Set the date for this request

Parameters

$date
DateTime
$date The DateTime object

Returns

Modulework\Modules\Http\Response
THIS
public string
# getDate( )

Returns the date of this response

Returns the date of this response

Returns

string
The Date
public Modulework\Modules\Http\Response
# setProtocolVersion( string $version = '1.0' )

Set the HTTP protocol version for this response

Set the HTTP protocol version for this response

Parameters

$version
string
$version The HTTP protocol version

Returns

Modulework\Modules\Http\Response
THIS
public string
# getProtocolVersion( )

Returns the HTTP protocol version of this response

Returns the HTTP protocol version of this response

Returns

string
The HTTP protocol version
public Modulework\Modules\Http\Response
# setExpires( DateTime $date = null )

Set the Expires HTTP header. To remove it pass NULL as parameter

Set the Expires HTTP header. To remove it pass NULL as parameter

Parameters

$date
DateTime|null
$date A \DateTime instance | null

Returns

Modulework\Modules\Http\Response
THIS
public DateTime
# getExpires( )

Get the Expires HTTP header (as \DateTime instance).

Get the Expires HTTP header (as \DateTime instance).

Returns

DateTime
The DateTime instance | null
public Modulework\Modules\Http\Response
# setCharset( string $charset )

Set the charset for this response

Set the charset for this response

Parameters

$charset
string
$version The charset

Returns

Modulework\Modules\Http\Response
THIS
public string
# getCharset( )

Returns the charset of this response

Returns the charset of this response

Returns

string
The charset
public boolean
# isSuccess( )

Is the response successful?

Is the response successful?

Returns

boolean
Whether the response is successful
public boolean
# isOk( )

Is the response OK?

Is the response OK?

Returns

boolean
Whether the response is OK
public boolean
# isNotFound( )

Is the response a not found error?

Is the response a not found error?

Returns

boolean
Whether the response is a not found error
public boolean
# isForbidden( )

Is the response forbidden?

Is the response forbidden?

Returns

boolean
Whether the response is forbidden
public boolean
# isRedirect( )

Is the response a redirect?

Is the response a redirect?

Returns

boolean
Whether the response is a redirect
public boolean
# isClientError( )

Is the response a client error?

Is the response a client error?

Returns

boolean
Whether the response is a client error
public boolean
# isServerError( )

Is the response a server error?

Is the response a server error?

Returns

boolean
Whether the response is a server error
public boolean
# isEmpty( )

Is the response empty?

Is the response empty?

Returns

boolean
Whether the response is empty
public boolean
# isInvalid( )

Is the response invalid?

Is the response invalid?

Returns

boolean
Whether the response is invalid
public boolean
# isInformational( )

Is the response informational?

Is the response informational?

Returns

boolean
Whether the response is informational
protected static boolean
# validateContent( mixed $content )

Validate the content Allowed types:

  • string
  • integers
  • objects implementing __toString()

Validate the content Allowed types:

  • string
  • integers
  • objects implementing __toString()

Parameters

$content
mixed
$content The content to check

Returns

boolean
Whether the content is valid

Magic methods summary

Properties summary

protected string $content
#

The main content

The main content

protected integer $statusCode
#

The HTTP status code

The HTTP status code

protected string $statusText
#

The HTTP status Text

The HTTP status Text

protected string $charset
#

The charset (header)

The charset (header)

protected string $protocolVersion
#

The HTTP protocol version

The HTTP protocol version

public static array $statusCodeRegistry
#

The status code registry List according to http://www.iana.org/assignments/http-status-codes/http-status-codes.txt

The status code registry List according to http://www.iana.org/assignments/http-status-codes/http-status-codes.txt

public Modulework\Modules\Http\Utilities\ArrayCase $headers
#

The headers to get sent

The headers to get sent

public Modulework\Modules\Http\Utilities\ArrayCase $cookies
#

The cookies to get sent

The cookies to get sent

protected Modulework\Modules\Http\Utilities\HeaderWrapperInterface $headerWrapper
#

The HeaderWrapper

The HeaderWrapper

API documentation generated by ApiGen 2.8.0