PHP Class Elgg\Http\ResponseFactory

Since: 2.3
Datei anzeigen Open project: elgg/elgg

Public Methods

Method Description
__construct ( Request $request, PluginHooksService $hooks, Service $ajax, Elgg\Http\ResponseTransport $transport ) Constructor
getHeaders ( boolean $remove_existing = true ) : ResponseHeaderBag Get headers set to apply to all responses
getSentResponse ( ) : Response | false Returns a response that was sent to the client
isAction ( ) : boolean Check if the requested path is an action
isXhr ( ) : boolean Check if the request is an XmlHttpRequest
normalize ( mixed $content = '' ) : mixed Normalizes content into serializable data by walking through arrays and objectifying Elgg entities
parseContext ( ) : string Parses response type to be used as plugin hook type
prepareRedirectResponse ( string $url, integer $status = 302, array $headers = [] ) : RedirectResponse Creates a redirect response
prepareResponse ( string $content = '', integer $status = 200, array $headers = [] ) : Response Creates an HTTP response
redirect ( string $forward_url = REFERRER, mixed $status_code = ELGG_HTTP_FOUND ) : RedirectResponse Prepares a redirect response
respond ( Elgg\Http\ResponseBuilder $response ) : Response Send HTTP response
respondFromContent ( string $content = '', integer $status_code = ELGG_HTTP_OK, array $headers = [] ) : type Send OK response
respondWithError ( string $error, integer $status_code = ELGG_HTTP_BAD_REQUEST, array $headers = [] ) : Response Send error HTTP response
send ( Response $response ) : Response Send a response
setHeader ( string $name, string $value, boolean $replace = true ) : void Sets headers to apply to all responses being sent
stringify ( mixed $content = '' ) : string Stringify/serialize response data
wrapLegacyAjaxResponse ( string $content = '', string $forward_url = REFERRER ) : string Wraps content for compability with legacy Elgg ajax calls

Method Details

__construct() public method

Constructor
public __construct ( Request $request, PluginHooksService $hooks, Service $ajax, Elgg\Http\ResponseTransport $transport )
$request Request HTTP request
$hooks Elgg\PluginHooksService Plugin hooks service
$ajax Elgg\Ajax\Service AJAX service
$transport Elgg\Http\ResponseTransport Response transport

getHeaders() public method

Get headers set to apply to all responses
public getHeaders ( boolean $remove_existing = true ) : ResponseHeaderBag
$remove_existing boolean Remove existing headers found in headers_list()
return Symfony\Component\HttpFoundation\ResponseHeaderBag

getSentResponse() public method

Returns a response that was sent to the client
public getSentResponse ( ) : Response | false
return Symfony\Component\HttpFoundation\Response | false

isAction() public method

Check if the requested path is an action
public isAction ( ) : boolean
return boolean

isXhr() public method

Check if the request is an XmlHttpRequest
public isXhr ( ) : boolean
return boolean

normalize() public method

Normalizes content into serializable data by walking through arrays and objectifying Elgg entities
public normalize ( mixed $content = '' ) : mixed
$content mixed Data to normalize
return mixed

parseContext() public method

Parses response type to be used as plugin hook type
public parseContext ( ) : string
return string

prepareRedirectResponse() public method

Creates a redirect response
public prepareRedirectResponse ( string $url, integer $status = 302, array $headers = [] ) : RedirectResponse
$url string URL to redirect to
$status integer The status code (302 by default)
$headers array An array of response headers (Location is always set to the given URL)
return Symfony\Component\HttpFoundation\RedirectResponse

prepareResponse() public method

Creates an HTTP response
public prepareResponse ( string $content = '', integer $status = 200, array $headers = [] ) : Response
$content string The response content
$status integer The response status code
$headers array An array of response headers
return Symfony\Component\HttpFoundation\Response

redirect() public method

Prepares a redirect response
public redirect ( string $forward_url = REFERRER, mixed $status_code = ELGG_HTTP_FOUND ) : RedirectResponse
$forward_url string Redirection URL
$status_code mixed HTTP status code or forward reason
return Symfony\Component\HttpFoundation\RedirectResponse

respond() public method

Send HTTP response
public respond ( Elgg\Http\ResponseBuilder $response ) : Response
$response Elgg\Http\ResponseBuilder ResponseBuilder instance An instance of an ErrorResponse, OkResponse or RedirectResponse
return Symfony\Component\HttpFoundation\Response

respondFromContent() public method

Send OK response
public respondFromContent ( string $content = '', integer $status_code = ELGG_HTTP_OK, array $headers = [] ) : type
$content string Response body
$status_code integer HTTP status code
$headers array HTTP headers (will be discarded for AJAX requets)
return type

respondWithError() public method

Send error HTTP response
public respondWithError ( string $error, integer $status_code = ELGG_HTTP_BAD_REQUEST, array $headers = [] ) : Response
$error string Error message
$status_code integer HTTP status code
$headers array HTTP headers (will be discarded on AJAX requests)
return Symfony\Component\HttpFoundation\Response

send() public method

Send a response
public send ( Response $response ) : Response
$response Symfony\Component\HttpFoundation\Response Response object
return Symfony\Component\HttpFoundation\Response

setHeader() public method

Sets headers to apply to all responses being sent
public setHeader ( string $name, string $value, boolean $replace = true ) : void
$name string Header name
$value string Header value
$replace boolean Replace existing headers
return void

stringify() public method

Casts objects implementing __toString method to strings Serializes non-scalar values to JSON
public stringify ( mixed $content = '' ) : string
$content mixed Content to serialize
return string

wrapLegacyAjaxResponse() public method

Wraps content for compability with legacy Elgg ajax calls
public wrapLegacyAjaxResponse ( string $content = '', string $forward_url = REFERRER ) : string
$content string Response content
$forward_url string Forward URL
return string