public respondFromOutput ( mixed $output, string $hook_type = '', boolean $try_decode = true ) : Symfony\Component\HttpFoundation\JsonResponse | ||
$output | mixed | Output from a page/action handler |
$hook_type | string | The hook type. If given, the response will be filtered by hook |
$try_decode | boolean | Try to convert a JSON string back to an abject |
return | Symfony\Component\HttpFoundation\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);
}
public function testCanNotSendANewResponseAfterAjaxResponseFromOutputIsSent() { $service = $this->createService(); ob_start(); $json_response = $this->ajax->respondFromOutput('foo'); ob_get_clean(); $this->assertEquals($json_response, $service->send($service->prepareResponse('bar'))); }