public function __invoke(Context $context, $next) { if (isset($this->options['allowedMethods'][$context->getMethod()])) { $contentType = $context->getRequest()->getContentType(); if (!isset($this->parsers[$contentType])) { throw new \Exception('Cannot found parser for ' . $contentType); } $parser = $this->parsers[$contentType]; $context = $parser($context); } $next($context); }
public function negotiate(Context $context) { $contentType = $context->getContentType(); if ($contentType) { return $contentType; } $ext = $context->getUri()->getExtension(); if ($ext && $this['accepts'][$ext]) { return $this['accepts'][$ext]; } $contentType = $context->getRequest()->getContentType(); if (!$contentType) { $accepted = $context->accepts(array_keys($this['accepts'])); if (isset($accepted)) { $contentType = is_string($this['accepts'][$accepted]) ? $this['accepts'][$accepted] : $accepted; } } if ($contentType) { return $this->match($contentType); } }