Since: 1.12.0
Inheritance: implements Elgg\Services\AjaxResponse
Example #1
0
 /**
  * Send a JSON HTTP response with the given output
  *
  * @param mixed  $output     Output from a page/action handler
  * @param string $hook_type  The hook type. If given, the response will be filtered by hook
  * @param bool   $try_decode Try to convert a JSON string back to an abject
  * @return void
  */
 public function respondFromOutput($output, $hook_type = '', $try_decode = true)
 {
     if ($try_decode) {
         $output = $this->decodeJson($output);
     }
     $api_response = new Response();
     $api_response->setData($output);
     $api_response = $this->filterApiResponse($api_response, $hook_type);
     $response = $this->buildHttpResponse($api_response);
     $this->response_sent = true;
     $response->send();
 }
Example #2
0
 /**
  * Send a JSON HTTP response with the given output
  *
  * @param mixed  $output     Output from a page/action handler
  * @param string $hook_type  The hook type. If given, the response will be filtered by hook
  * @param bool   $try_decode Try to convert a JSON string back to an abject
  * @return JsonResponse
  */
 public function respondFromOutput($output, $hook_type = '', $try_decode = true)
 {
     if ($try_decode) {
         $output = $this->decodeJson($output);
     }
     $api_response = new Response();
     $api_response->setData((object) ['value' => $output]);
     $api_response = $this->filterApiResponse($api_response, $hook_type);
     $response = $this->buildHttpResponse($api_response);
     $this->response_sent = true;
     return _elgg_services()->responseFactory->send($response);
 }