function call()
{
$app = $this->app;
$res = $app->response();
try {
$this->next->call();
if (self::$disabled) {
return;
}
if ($res->status() !== 200) {
return;
}
$res['Content-Type'] = 'application/json';
$result = self::prepForEncoding(self::$result);
$res->status(200);
} catch (Exception $e) {
if ($e instanceof PDOException) {
$log = $app->getLog();
foreach (ORM::get_query_log() as $entry) {
$log->debug($entry);
}
}
$res['Content-Type'] = 'application/json';
$result = array('error' => $e->getMessage());
$log = $app->getLog();
$log->debug($e->getMessage() . "\n" . $e->getTraceAsString());
if ($e instanceof AccessException) {
$res->status($e->getCode());
} else {
$res->status(500);
}
}
// encode
$res->write(defined('JSON_PRETTY_PRINT') ? json_encode($result, JSON_PRETTY_PRINT & JSON_NUMERIC_CHECK) : json_encode($result, JSON_NUMERIC_CHECK));
}