|
Elgg
Version master
|
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 (mixed $output, string $event_type='', bool $try_decode=true) | |
| Send a JSON HTTP response with the given output. More... | |
| respondWithError (string $msg='', int $status=400) | |
| Send a JSON HTTP 400 response. 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 36 of file Service.php.
| Elgg\Ajax\Service::decodeJson | ( | $string | ) |
Attempt to JSON decode the given string.
| mixed | $string | Output string |
Definition at line 74 of file Service.php.
| Elgg\Ajax\Service::getViews | ( | ) |
Returns an array of views allowed for ajax calls.
Definition at line 198 of file Service.php.
| Elgg\Ajax\Service::isAjax2Request | ( | ) |
Did the request come from the elgg/Ajax module?
Definition at line 50 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 63 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 178 of file Service.php.
| Elgg\Ajax\Service::respondFromOutput | ( | mixed | $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 92 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 161 of file Service.php.
| Elgg\Ajax\Service::unregisterView | ( | string | $view | ) |
Unregister a view for ajax calls.
| string | $view | The view name |
Definition at line 189 of file Service.php.
|
protected |
Definition at line 25 of file Service.php.
|
protected |
Definition at line 23 of file Service.php.