Sort equal routes by HTTP method

This commit is contained in:
Jordi Boggiano 2012-04-13 10:48:25 +02:00
parent 8426a3a70e
commit e2af9b3fc4

View File

@ -69,12 +69,21 @@ class ApiDocExtractor
}
}
usort($array, function($a, $b) {
$methodOrder = array('GET', 'POST', 'PUT', 'DELETE');
usort($array, function($a, $b) use ($methodOrder) {
if ($a['resource'] === $b['resource']) {
if ($a['route']->getPattern() === $b['route']->getPattern()) {
$methodA = array_search($a['route']->getRequirement('_method'), $methodOrder);
$methodB = array_search($b['route']->getRequirement('_method'), $methodOrder);
if ($methodA === $methodB) {
return strcmp($a['route']->getRequirement('_method'), $b['route']->getRequirement('_method'));
}
return $methodA > $methodB ? 1 : -1;
}
return strcmp($a['route']->getPattern(), $b['route']->getPattern());
}