39 $message_filter = [$this,
'prepareResponse'];
49 $version = $this->request->headers->get(
'X-Elgg-Ajax-API');
74 if (!is_string($string)) {
98 $api_response->setData(
$output);
100 $api_response->setData((
object)
$output);
102 $api_response->setData((
object) [
'value' =>
$output]);
105 $api_response = $this->filterApiResponse($api_response, $event_type);
106 $response = $this->buildHttpResponse($api_response);
108 $this->response_sent =
true;
121 $api_response = $this->filterApiResponse($api_response, $event_type);
122 $response = $this->buildHttpResponse($api_response);
124 $this->response_sent =
true;
137 $response =
new JsonResponse([
'error' => $msg], $status);
140 $this->msgs->dumpRegister();
142 $this->response_sent =
true;
156 $api_response->
setTtl($this->request->getParam(
'elgg_response_ttl', 0,
false));
160 $api_response = $this->events->triggerResults($event_name, $event_type, [], $api_response);
162 throw new RuntimeException(
"The value returned by event [{$event_name}, {$event_type}] was not an ApiResponse");
166 return $api_response;
177 private function buildHttpResponse(
AjaxResponse $api_response): JsonResponse {
179 return new JsonResponse([
'error' =>
'The response was cancelled'], 400);
184 $ttl = $api_response->
getTtl();
187 $response->headers->remove(
'Cache-Control');
192 $response->headers->set(
'Expires', gmdate(
'D, d M Y H:i:s \G\M\T', time() + $ttl));
212 if ($this->request->getParam(
'elgg_fetch_messages',
true)) {
223 if ($this->request->getParam(
'elgg_fetch_deps',
true)) {
224 $response->getData()->_elgg_deps = $this->esm->getImports();
238 $this->allowed_views[
$view] =
true;
249 unset($this->allowed_views[$view]);
258 return array_keys($this->allowed_views);
isCancelled()
Has the response been cancelled?
respondFromOutput($output, string $event_type= '', bool $try_decode=true)
Send a JSON HTTP response with the given output.
Exception thrown if an error which can only be found on runtime occurs.
Keeps track of ES modules.
setTtl($ttl=0)
Set the max-age for client caching.
isAjax2Request()
Did the request come from the elgg/Ajax module?
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
registerView(string $view)
Register a view to be available for ajax calls.
respondWithError(string $msg= '', int $status=400)
Send a JSON HTTP 400 response.
Models the Ajax API service.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
prepareResponse(\Elgg\Event $event)
Prepare the response with additional metadata, like system messages and required ES modules...
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
__construct(protected EventsService $events, protected SystemMessagesService $msgs, protected Request $request, protected ESMService $esm)
Constructor.
decodeJson($string)
Attempt to JSON decode the given string.
unregisterView(string $view)
Unregister a view for ajax calls.
respondFromApiResponse(AjaxResponse $api_response, string $event_type= '')
Send a JSON HTTP response based on the given API response.
if($email instanceof\Elgg\Email) $object
getData()
Get the response data, which will be a stdClass object with property "value".
isReady()
Is the service ready to respond to the request?
_elgg_services()
Get the global service provider.
getTtl()
Get the max-age for client caching.
getViews()
Returns an array of views allowed for ajax calls.
Models an event passed to event handlers.