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

Commit

Permalink
refactoring view strategy priorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Freeaqingme committed Jul 14, 2012
1 parent 4dc27f8 commit 79b036a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
28 changes: 15 additions & 13 deletions src/Strategy/FeedStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,25 @@ public function selectRenderer(ViewEvent $e)
}

$headers = $request->getHeaders();
if ($headers->has('accept')) {
$accept = $headers->get('accept');
if (!$headers->has('accept')) {
return;
}

$match = $accept->match('application/rss+xml, application/atom+xml');
if ($match && $match->getTypeString() == 'application/rss+xml') {
$this->renderer->setFeedType('rss');
return $this->renderer;
}
$accept = $headers->get('accept');
if (($match = $accept->match('application/rss+xml, application/atom+xml')) == false) {
return;
}

if ($match && $match->getTypeString() == 'application/atom+xml') {
$this->renderer->setFeedType('atom');
return $this->renderer;
}
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
32 changes: 16 additions & 16 deletions src/Strategy/JsonStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,27 @@ public function selectRenderer(ViewEvent $e)
}

$headers = $request->getHeaders();
if ($headers->has('accept')) {
$accept = $headers->get('Accept');
if (!$headers->has('accept')) {
return;
}

$match = $accept->match('application/json, application/javascript');

if ($match && $match->getFormat() == 'json') {
// application/json Accept header found
return $this->renderer;
}
$accept = $headers->get('Accept');
if (($match = $accept->match('application/json, application/javascript')) == false) {
return;
}

if ($match) {
// application/javascript Accept header found
if (false != ($callback = $request->getQuery()->get('callback'))) {
$this->renderer->setJsonpCallback($callback);
}
return $this->renderer;
}
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

0 comments on commit 79b036a

Please sign in to comment.