Skip to content

Commit

Permalink
Allowing multiple suffixes in one Route::group
Browse files Browse the repository at this point in the history
  • Loading branch information
pcockwell committed Jul 17, 2013
1 parent 479325a commit 8641879
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
10 changes: 9 additions & 1 deletion app/lib/autodo/src/Autodo/Routing/RouteCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,15 @@ private static function compilePattern(Route $route, $pattern, $isHost)
$regexp .= self::computeRegexp($tokens, $i, $firstOptional);
}

$regexp .= $route->getOption('_suffix') ?: '';
$suffix = $route->getOption('_suffix') ?: '';
if (!is_array($suffix))
{
$regexp .= $suffix;
}
else
{
$regexp .= '('.implode('|', $suffix).')';
}

return array(
'staticPrefix' => 'text' === $tokens[0][0] ? $tokens[0][1] : '',
Expand Down
18 changes: 15 additions & 3 deletions app/lib/autodo/src/Autodo/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ protected function getGroupSuffix()

if (isset($group['suffix']))
{
if (is_array($group['suffix'])) return implode('/', $group['suffix']);

return $group['suffix'];
}
}
Expand All @@ -139,6 +137,20 @@ protected function mergeGroupSuffix($action)
{
$suffix = isset($action['suffix']) ? $action['suffix'] : '';

return trim($suffix.'/'.$this->getGroupSuffix(), '/');
$groupSuffix = $this->getGroupSuffix();
if (!is_array($groupSuffix))
{
return trim($suffix.'/'.$groupSuffix, '/');
}
else
{
$mergedSuffixes = array();
foreach($groupSuffix as $currentSuffix)
{
$mergedSuffixes[] = trim($suffix.'/'.$currentSuffix, '/');
}
return $mergedSuffixes;
}

}
}
4 changes: 1 addition & 3 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
$new_input[$key] = $content;
}
}
//$new_path = str_replace('.json', '', Request::path());
//return Redirect::to($new_path)->withInput($new_input);
Input::replace($new_input);
}
else
Expand All @@ -76,7 +74,7 @@
return View::make('users')->with('users', $users);
});

Route::group(array('suffix' => '.json'), function()
Route::group(array('suffix' => array('.json', '.xml')), function()
{
// Controller to handle user accounts.
Route::controller('user', 'UserController');
Expand Down

0 comments on commit 8641879

Please sign in to comment.