Elgg  Version 3.0
Public Member Functions | Protected Member Functions | List of all members
Elgg\Http\ResponseFactory Class Reference

WARNING: API IN FLUX. More...

Public Member Functions

 __construct (Request $request, PluginHooksService $hooks, AjaxService $ajax, ResponseTransport $transport, EventsService $events)
 Constructor. More...
 
 setHeader ($name, $value, $replace=true)
 Sets headers to apply to all responses being sent. More...
 
 setCookie (\ElggCookie $cookie)
 Set a cookie, but allow plugins to customize it first. More...
 
 getHeaders ($remove_existing=true)
 Get headers set to apply to all responses. More...
 
 prepareResponse ($content= '', $status=200, array $headers=[])
 Creates an HTTP response. More...
 
 prepareRedirectResponse ($url, $status=302, array $headers=[])
 Creates a redirect response. More...
 
 prepareJsonResponse ($content= '', $status=200, array $headers=[])
 Creates an JSON response. More...
 
 send (Response $response)
 Send a response. More...
 
 getSentResponse ()
 Returns a response that was sent to the client. More...
 
 respond (ResponseBuilder $response)
 Send HTTP response. More...
 
 respondWithError ($error, $status_code=ELGG_HTTP_BAD_REQUEST, array $headers=[])
 Send error HTTP response. More...
 
 respondFromContent ($content= '', $status_code=ELGG_HTTP_OK, array $headers=[])
 Send OK response. More...
 
 wrapAjaxResponse ($content= '', $forward_url=null)
 Wraps response content in an Ajax2 compatible format. More...
 
 wrapLegacyAjaxResponse ($content= '', $forward_url=REFERRER)
 Wraps content for compability with legacy Elgg ajax calls. More...
 
 redirect ($forward_url=REFERRER, $status_code=ELGG_HTTP_FOUND)
 Prepares a redirect response. More...
 
 parseContext ()
 Parses response type to be used as plugin hook type. More...
 
 isXhr ()
 Check if the request is an XmlHttpRequest. More...
 
 isAction ()
 Check if the requested path is an action. More...
 
 normalize ($content= '')
 Normalizes content into serializable data by walking through arrays and objectifying Elgg entities. More...
 
 stringify ($content= '')
 Stringify/serialize response data. More...
 
 setTransport (ResponseTransport $transport)
 Replaces response transport. More...
 

Protected Member Functions

 getSiteRefererUrl ()
 Ensures the referer header is a site url. More...
 
 makeSecureForwardUrl ($url)
 Ensure the url has a valid protocol for browser use. More...
 
 closeSession ()
 Closes the session. More...
 

Detailed Description

WARNING: API IN FLUX.

DO NOT USE DIRECTLY.

Since
2.3

Definition at line 23 of file ResponseFactory.php.

Constructor & Destructor Documentation

Elgg\Http\ResponseFactory::__construct ( Request  $request,
PluginHooksService  $hooks,
AjaxService  $ajax,
ResponseTransport  $transport,
EventsService  $events 
)

Constructor.

Parameters
Request$requestHTTP request
PluginHooksService$hooksPlugin hooks service
AjaxService$ajaxAJAX service
ResponseTransport$transportResponse transport
EventsService$eventsEvents service

Definition at line 69 of file ResponseFactory.php.

Member Function Documentation

Elgg\Http\ResponseFactory::closeSession ( )
protected

Closes the session.

Force closing the session so session is saved to the database before headers are sent preventing race conditions with session data

See also
https://github.com/Elgg/Elgg/issues/12348
Returns
void

Definition at line 748 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::getHeaders (   $remove_existing = true)

Get headers set to apply to all responses.

Parameters
bool$remove_existingRemove existing headers found in headers_list()
Returns
ResponseHeaderBag

Definition at line 124 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::getSentResponse ( )

Returns a response that was sent to the client.

Returns
Response|false

Definition at line 271 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::getSiteRefererUrl ( )
protected

Ensures the referer header is a site url.

Returns
string

Definition at line 712 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::isAction ( )

Check if the requested path is an action.

Returns
bool

Definition at line 651 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::isXhr ( )

Check if the request is an XmlHttpRequest.

Returns
bool

Definition at line 643 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::makeSecureForwardUrl (   $url)
protected

Ensure the url has a valid protocol for browser use.

Parameters
string$urlurl the secure
Returns
string

Definition at line 729 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::normalize (   $content = '')

Normalizes content into serializable data by walking through arrays and objectifying Elgg entities.

Parameters
mixed$contentData to normalize
Returns
mixed

Definition at line 665 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::parseContext ( )

Parses response type to be used as plugin hook type.

Returns
string

Definition at line 611 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::prepareJsonResponse (   $content = '',
  $status = 200,
array  $headers = [] 
)

Creates an JSON response.

Parameters
mixed$contentThe response content
integer$statusThe response status code
array$headersAn array of response headers
Returns
JsonResponse
Exceptions
InvalidArgumentException

Removing Content-Type header because in some cases content-type headers were already set This is a problem when serving a cachable view (for example a .css) in ajax/view

See also
https://github.com/Elgg/Elgg/issues/9794

Definition at line 191 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::prepareRedirectResponse (   $url,
  $status = 302,
array  $headers = [] 
)

Creates a redirect response.

Parameters
string$urlURL to redirect to
integer$statusThe status code (302 by default)
array$headersAn array of response headers (Location is always set to the given URL)
Returns
SymfonyRedirectResponse
Exceptions
InvalidArgumentException

Definition at line 172 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::prepareResponse (   $content = '',
  $status = 200,
array  $headers = [] 
)

Creates an HTTP response.

Parameters
mixed$contentThe response content
integer$statusThe response status code
array$headersAn array of response headers
Returns
Response
Exceptions
InvalidArgumentException

Definition at line 153 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::redirect (   $forward_url = REFERRER,
  $status_code = ELGG_HTTP_FOUND 
)

Prepares a redirect response.

Parameters
string$forward_urlRedirection URL
mixed$status_codeHTTP status code or forward reason
Returns
SymfonyRedirectResponse
Exceptions
InvalidParameterException

Definition at line 519 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::respond ( ResponseBuilder  $response)

Send HTTP response.

Parameters
ResponseBuilder$responseResponseBuilder instance An instance of an ErrorResponse, OkResponse or RedirectResponse
Returns
Response
Exceptions

Definition at line 283 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::respondFromContent (   $content = '',
  $status_code = ELGG_HTTP_OK,
array  $headers = [] 
)

Send OK response.

Parameters
string$contentResponse body
int$status_codeHTTP status code
array$headersHTTP headers (will be discarded for AJAX requests)
Returns
Response|false

Definition at line 419 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::respondWithError (   $error,
  $status_code = ELGG_HTTP_BAD_REQUEST,
array  $headers = [] 
)

Send error HTTP response.

Parameters
string$errorError message
int$status_codeHTTP status code
array$headersHTTP headers (will be discarded on AJAX requests)
Returns
Response
Exceptions

Definition at line 365 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::send ( Response  $response)

Send a response.

Parameters
Response$responseResponse object
Returns
Response|false

Definition at line 234 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::setCookie ( \ElggCookie  $cookie)

Set a cookie, but allow plugins to customize it first.

To customize all cookies, register for the 'init:cookie', 'all' event.

Parameters
\ElggCookie$cookieThe cookie that is being set
Returns
bool

Definition at line 99 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::setHeader (   $name,
  $value,
  $replace = true 
)

Sets headers to apply to all responses being sent.

Parameters
string$nameHeader name
string$valueHeader value
bool$replaceReplace existing headers
Returns
void

Definition at line 87 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::setTransport ( ResponseTransport  $transport)

Replaces response transport.

Parameters
ResponseTransport$transportTransport interface
Returns
void

Definition at line 703 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::stringify (   $content = '')

Stringify/serialize response data.

Casts objects implementing __toString method to strings Serializes non-scalar values to JSON

Parameters
mixed$contentContent to serialize
Returns
string

Definition at line 686 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::wrapAjaxResponse (   $content = '',
  $forward_url = null 
)

Wraps response content in an Ajax2 compatible format.

Parameters
string$contentResponse content
string$forward_urlForward URL
Returns
string

Definition at line 437 of file ResponseFactory.php.

Elgg\Http\ResponseFactory::wrapLegacyAjaxResponse (   $content = '',
  $forward_url = REFERRER 
)

Wraps content for compability with legacy Elgg ajax calls.

Parameters
string$contentResponse content
string$forward_urlForward URL
Returns
string

Definition at line 467 of file ResponseFactory.php.


The documentation for this class was generated from the following file: