public function __invoke(Context $context, $next = null) { // avoid content negotiator on cli if ($context->getApp()->isCli()) { $next($context); return; } // set response content type by negotiating to context $contentType = $this->negotiate($context); if ($contentType) { $context->withContentType($contentType); } $next($context); // render respect response content type $contentType = $context->getContentType(); if (isset($this['renderers'][$contentType])) { $handler = $this['renderers'][$contentType]->getHandler(); $handler($context); } }