/**
* Listen to the render event
*
* @param MvcEvent $e
*/
public static function onRender(MvcEvent $e)
{
if (!$e->isError()) {
return;
}
if (self::$acceptFilter != '*') {
$headers = $e->getRequest()->getHeaders();
if (!$headers->has('Accept')) {
return;
}
$match = $headers->get('Accept')->match(self::$acceptFilter);
if (!$match || $match->getTypeString() == '*/*') {
return;
}
}
$model = $e->getResult();
if (!$model instanceof ModelInterface) {
return;
}
$exception = $model->getVariable('exception');
if (!$exception instanceof Exception) {
return;
}
$jsonModel = new JsonModel(array('api-problem' => new ApiProblem($exception->getCode(), $exception)));
$e->setResult($jsonModel);
$e->setViewModel($jsonModel);
}