|
Elgg
Version 6.3
|
Models the Ajax API service. More...
Public Member Functions | |
| __construct (protected EventsService $events, protected SystemMessagesService $msgs, protected Request $request, protected ESMService $esm, protected ExternalFiles $externalFiles) | |
| 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, string $event_type='', bool $try_decode=true) | |
| Send a JSON HTTP response with the given output. More... | |
| respondFromApiResponse (AjaxResponse $api_response, string $event_type='') | |
| Send a JSON HTTP response based on the given API response. More... | |
| respondWithError (string $msg='', int $status=400) | |
| Send a JSON HTTP 400 response. More... | |
| prepareResponse (\Elgg\Event $event) | |
| Prepare the response with additional metadata, like system messages and required ES modules. More... | |
| registerView (string $view) | |
| Register a view to be available for ajax calls. More... | |
| unregisterView (string $view) | |
| Unregister a view for ajax calls. More... | |
| getViews () | |
| Returns an array of views allowed for ajax calls. More... | |
Protected Attributes | |
| bool | $response_sent = false |
| array | $allowed_views = [] |
| Elgg\Ajax\Service::__construct | ( | protected EventsService | $events, |
| protected SystemMessagesService | $msgs, | ||
| protected Request | $request, | ||
| protected ESMService | $esm, | ||
| protected ExternalFiles | $externalFiles | ||
| ) |
Constructor.
| EventsService | $events | Events service |
| SystemMessagesService | $msgs | System messages service |
| Request | $request | Http Request |
| ESMService | $esm | ESM service |
| ExternalFiles | $externalFiles | External files service |
Definition at line 35 of file Service.php.
| Elgg\Ajax\Service::decodeJson | ( | $string | ) |
Attempt to JSON decode the given string.
| mixed | $string | Output string |
Definition at line 76 of file Service.php.
| Elgg\Ajax\Service::getViews | ( | ) |
Returns an array of views allowed for ajax calls.
Definition at line 278 of file Service.php.
| Elgg\Ajax\Service::isAjax2Request | ( | ) |
Did the request come from the elgg/Ajax module?
Definition at line 51 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 65 of file Service.php.
| Elgg\Ajax\Service::prepareResponse | ( | \Elgg\Event | $event | ) |
Prepare the response with additional metadata, like system messages and required ES modules.
| \Elgg\Event | $event | "ajax_response", "all" |
Definition at line 209 of file Service.php.
| Elgg\Ajax\Service::registerView | ( | string | $view | ) |
Register a view to be available for ajax calls.
| string | $view | The view name |
Definition at line 258 of file Service.php.
| Elgg\Ajax\Service::respondFromApiResponse | ( | AjaxResponse | $api_response, |
| string | $event_type = '' |
||
| ) |
Send a JSON HTTP response based on the given API response.
| AjaxResponse | $api_response | API response |
| string | $event_type | The event type. If given, the response will be filtered by event |
Definition at line 123 of file Service.php.
| Elgg\Ajax\Service::respondFromOutput | ( | $output, | |
| string | $event_type = '', |
||
| bool | $try_decode = true |
||
| ) |
Send a JSON HTTP response with the given output.
| mixed | $output | Output from a page/action handler |
| string | $event_type | The event type. If given, the response will be filtered by event |
| bool | $try_decode | Try to convert a JSON string back to an abject |
Definition at line 94 of file Service.php.
| Elgg\Ajax\Service::respondWithError | ( | string | $msg = '', |
| int | $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 139 of file Service.php.
| Elgg\Ajax\Service::unregisterView | ( | string | $view | ) |
Unregister a view for ajax calls.
| string | $view | The view name |
Definition at line 269 of file Service.php.
|
protected |
Definition at line 24 of file Service.php.
|
protected |
Definition at line 22 of file Service.php.