Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | List of all members
Elgg\Ajax\Service Class Reference

Models the Ajax API service. More...

Public Member Functions

 __construct (PluginHooksService $hooks, SystemMessagesService $msgs, Input $input, Config $amdConfig)
 Constructor. More...
 
 isAjax2Request ()
 Did the request come from the elgg/Ajax module? More...
 
 isReady ()
 Is the service ready to respond to the request? More...
 
 decodeJson ($string)
 Attempt to JSON decode the given string. More...
 
 respondFromOutput ($output, $hook_type= '', $try_decode=true)
 Send a JSON HTTP response with the given output. More...
 
 respondFromApiResponse (AjaxResponse $api_response, $hook_type= '')
 Send a JSON HTTP response based on the given API response. More...
 
 respondWithError ($msg, $status=400)
 Send a JSON HTTP 400 response. More...
 
 appendMessages ($hook, $type, AjaxResponse $response, $params)
 Send system messages back with the response. More...
 
 appendDeps ($hook, $type, AjaxResponse $response, $params)
 Send required AMD modules list back with the response. More...
 

Detailed Description

Models the Ajax API service.

Since
1.12.0 private

Definition at line 19 of file Service.php.

Constructor & Destructor Documentation

Elgg\Ajax\Service::__construct ( PluginHooksService  $hooks,
SystemMessagesService  $msgs,
Input  $input,
Config  $amdConfig 
)

Constructor.

Parameters
PluginHooksService$hooksHooks service
SystemMessagesService$msgsSystem messages service
Input$inputInput service
Config$amdConfigAMD config

Definition at line 54 of file Service.php.

Member Function Documentation

Elgg\Ajax\Service::appendDeps (   $hook,
  $type,
AjaxResponse  $response,
  $params 
)

Send required AMD modules list back with the response.

Parameters
string$hook"ajax_response"
string$type"all"
AjaxResponse$responseAjax response
array$paramsHook params
Returns
AjaxResponse private

Definition at line 249 of file Service.php.

Elgg\Ajax\Service::appendMessages (   $hook,
  $type,
AjaxResponse  $response,
  $params 
)

Send system messages back with the response.

Parameters
string$hook"ajax_response"
string$type"all"
AjaxResponse$responseAjax response
array$paramsHook params
Returns
AjaxResponse private

Definition at line 232 of file Service.php.

Elgg\Ajax\Service::decodeJson (   $string)

Attempt to JSON decode the given string.

Parameters
mixed$stringOutput string
Returns
mixed

Definition at line 100 of file Service.php.

Elgg\Ajax\Service::isAjax2Request ( )

Did the request come from the elgg/Ajax module?

Returns
bool

Definition at line 76 of file Service.php.

Elgg\Ajax\Service::isReady ( )

Is the service ready to respond to the request?

Some code paths involve multiple layers of handling (e.g. router calls actions/ajax views) so we must check whether the response has already been sent to avoid sending it twice. We can't use headers_sent() because Router needs to use output buffering.

Returns
bool

Definition at line 90 of file Service.php.

Elgg\Ajax\Service::respondFromApiResponse ( AjaxResponse  $api_response,
  $hook_type = '' 
)

Send a JSON HTTP response based on the given API response.

Parameters
AjaxResponse$api_responseAPI response
string$hook_typeThe hook type. If given, the response will be filtered by hook
Returns
void

Definition at line 139 of file Service.php.

Elgg\Ajax\Service::respondFromOutput (   $output,
  $hook_type = '',
  $try_decode = true 
)

Send a JSON HTTP response with the given output.

Parameters
mixed$outputOutput from a page/action handler
string$hook_typeThe hook type. If given, the response will be filtered by hook
bool$try_decodeTry to convert a JSON string back to an abject
Returns
void

Definition at line 116 of file Service.php.

Elgg\Ajax\Service::respondWithError (   $msg,
  $status = 400 
)

Send a JSON HTTP 400 response.

Parameters
string$msgThe error message (not displayed to the user)
int$statusThe HTTP status code
Returns
void

Definition at line 154 of file Service.php.


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