public function after(Request $request, Response $response, Application $app)
{
if ($response->isRedirection()) {
return;
}
// if ('application/json' === $request->headers->get('Accept')) {
// return $this->app()->json($this->data);
// }
//https://blog.yorunohikage.fr/
//Pretty printing all JSON output in Silex PHP
//if($response instanceof JsonResponse) {
// $response->setEncodingOptions(JSON_PRETTY_PRINT);
//}
if ($request->isXmlHttpRequest()) {
$response_data = array('status' => 'OK', 'data' => $this->data);
if (!is_null($this->error)) {
$response_data['status'] = 'ERROR';
$response_data['error'] = $this->error;
}
return $this->app->json($response_data);
}
if ($response->getContent() == '') {
$this->initTwig();
$response->setContent($this->twig()->render($this->template, $this->data));
}
}