Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'Freeaqingme/acceptHandling'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Jul 14, 2012
7 parents 19f0ef6 + 33bf9c0 + 3729984 + a5ce396 + 698dbe0 + 0efca0b + 79b036a commit e3b1be1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
33 changes: 17 additions & 16 deletions src/Strategy/FeedStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
36 changes: 19 additions & 17 deletions src/Strategy/JsonStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Strategy/PhpRendererStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e3b1be1

Please sign in to comment.