diff --git a/src/Strategy/FeedStrategy.php b/src/Strategy/FeedStrategy.php index 7cfc5c6c..cca82db2 100644 --- a/src/Strategy/FeedStrategy.php +++ b/src/Strategy/FeedStrategy.php @@ -98,24 +98,25 @@ public function selectRenderer(ViewEvent $e) } $headers = $request->getHeaders(); - if ($headers->has('accept')) { - $accept = $headers->get('accept'); - foreach ($accept->getPrioritized() as $mediaType) { - if (0 === strpos($mediaType, 'application/rss+xml')) { - // application/rss+xml Accept header found - $this->renderer->setFeedType('rss'); - return $this->renderer; - } - if (0 === strpos($mediaType, 'application/atom+xml')) { - // application/atom+xml Accept header found - $this->renderer->setFeedType('atom'); - return $this->renderer; - } - } + if (!$headers->has('accept')) { + return; + } + + $accept = $headers->get('accept'); + if (($match = $accept->match('application/rss+xml, application/atom+xml')) == false) { + return; + } + + if ($match->getTypeString() == 'application/rss+xml') { + $this->renderer->setFeedType('rss'); + return $this->renderer; + } + + if ($match->getTypeString() == 'application/atom+xml') { + $this->renderer->setFeedType('atom'); + return $this->renderer; } - // Not matched! - return; } /** diff --git a/src/Strategy/JsonStrategy.php b/src/Strategy/JsonStrategy.php index 2a11f7d7..9d7c8206 100644 --- a/src/Strategy/JsonStrategy.php +++ b/src/Strategy/JsonStrategy.php @@ -97,25 +97,27 @@ public function selectRenderer(ViewEvent $e) } $headers = $request->getHeaders(); - if ($headers->has('accept')) { - $accept = $headers->get('Accept'); - foreach ($accept->getPrioritized() as $mediaType) { - if (0 === strpos($mediaType, 'application/json')) { - // application/json Accept header found - return $this->renderer; - } - if (0 === strpos($mediaType, 'application/javascript')) { - // application/javascript Accept header found - if (false != ($callback = $request->getQuery()->get('callback'))) { - $this->renderer->setJsonpCallback($callback); - } - return $this->renderer; - } - } + if (!$headers->has('accept')) { + return; + } + + + $accept = $headers->get('Accept'); + if (($match = $accept->match('application/json, application/javascript')) == false) { + return; + } + + if ($match->getFormat() == 'json') { + // application/json Accept header found + return $this->renderer; + } + + // application/javascript Accept header found + if (false != ($callback = $request->getQuery()->get('callback'))) { + $this->renderer->setJsonpCallback($callback); } - // Not matched! - return; + return $this->renderer; } /** diff --git a/src/Strategy/PhpRendererStrategy.php b/src/Strategy/PhpRendererStrategy.php index 86c0374f..95b11bf9 100644 --- a/src/Strategy/PhpRendererStrategy.php +++ b/src/Strategy/PhpRendererStrategy.php @@ -130,7 +130,7 @@ public function selectRenderer(ViewEvent $e) * Populates the content of the response object from the view rendering * results. * - * @param ViewEvent $e + * @param ViewEvent $e * @return void */ public function injectResponse(ViewEvent $e)