Elgg
Version 4.3
|
Models the Ajax API service. More...
Public Member Functions | |
__construct (PluginHooksService $hooks, SystemMessagesService $msgs, Request $request, 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... | |
prepareResponse (\Elgg\Hook $hook) | |
Prepare the response with additional metadata, like system messages and required AMD modules. More... | |
registerView ($view) | |
Register a view to be available for ajax calls. More... | |
unregisterView ($view) | |
Unregister a view for ajax calls. More... | |
getViews () | |
Returns an array of views allowed for ajax calls. More... | |
Elgg\Ajax\Service::__construct | ( | PluginHooksService | $hooks, |
SystemMessagesService | $msgs, | ||
Request | $request, | ||
Config | $amdConfig | ||
) |
Constructor.
PluginHooksService | $hooks | Hooks service |
SystemMessagesService | $msgs | System messages service |
Request | $request | Http Request |
Config | $amdConfig | AMD config |
Definition at line 59 of file Service.php.
Elgg\Ajax\Service::decodeJson | ( | $string | ) |
Attempt to JSON decode the given string.
mixed | $string | Output string |
Definition at line 99 of file Service.php.
Elgg\Ajax\Service::getViews | ( | ) |
Returns an array of views allowed for ajax calls.
Definition at line 289 of file Service.php.
Elgg\Ajax\Service::isAjax2Request | ( | ) |
Did the request come from the elgg/Ajax module?
Definition at line 74 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.
Definition at line 88 of file Service.php.
Elgg\Ajax\Service::prepareResponse | ( | \Elgg\Hook | $hook | ) |
Prepare the response with additional metadata, like system messages and required AMD modules.
\Elgg\Hook | $hook | "ajax_response", "all" |
Definition at line 238 of file Service.php.
Elgg\Ajax\Service::registerView | ( | $view | ) |
Register a view to be available for ajax calls.
string | $view | The view name |
Definition at line 269 of file Service.php.
Elgg\Ajax\Service::respondFromApiResponse | ( | AjaxResponse | $api_response, |
$hook_type = '' |
|||
) |
Send a JSON HTTP response based on the given API response.
AjaxResponse | $api_response | API response |
string | $hook_type | The hook type. If given, the response will be filtered by hook |
Definition at line 144 of file Service.php.
Elgg\Ajax\Service::respondFromOutput | ( | $output, | |
$hook_type = '' , |
|||
$try_decode = true |
|||
) |
Send a JSON HTTP response with the given output.
mixed | $output | Output from a page/action handler |
string | $hook_type | The hook type. If given, the response will be filtered by hook |
bool | $try_decode | Try to convert a JSON string back to an abject |
Definition at line 116 of file Service.php.
Elgg\Ajax\Service::respondWithError | ( | $msg = '' , |
|
$status = 400 |
|||
) |
Send a JSON HTTP 400 response.
string | $msg | The error message (not displayed to the user) |
int | $status | The HTTP status code |
Definition at line 160 of file Service.php.
Elgg\Ajax\Service::unregisterView | ( | $view | ) |
Unregister a view for ajax calls.
string | $view | The view name |
Definition at line 280 of file Service.php.