Router: allow HEAD method to be defined first

This commit is contained in:
David Badura 2017-07-21 19:43:13 +02:00
parent adeab151ba
commit 52e2821597
3 changed files with 21 additions and 1 deletions

View File

@ -307,7 +307,7 @@ EOF;
if (in_array('GET', $methods)) {
// Since we treat HEAD requests like GET requests we don't need to match it.
$methodVariable = 'canonicalMethod';
$methods = array_filter($methods, function ($method) { return 'HEAD' !== $method; });
$methods = array_values(array_filter($methods, function ($method) { return 'HEAD' !== $method; }));
}
if (1 === count($methods)) {

View File

@ -57,6 +57,17 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
}
not_head_and_get:
// get_and_head
if ('/get_and_head' === $pathinfo) {
if ('GET' !== $canonicalMethod) {
$allow[] = 'GET';
goto not_get_and_head;
}
return array('_route' => 'get_and_head');
}
not_get_and_head:
// post_and_head
if ('/post_and_get' === $pathinfo) {
if (!in_array($requestMethod, array('POST', 'HEAD'))) {

View File

@ -297,6 +297,15 @@ class PhpMatcherDumperTest extends TestCase
array(),
'',
array(),
array('HEAD', 'GET')
));
$headMatchCasesCollection->add('get_and_head', new Route(
'/get_and_head',
array(),
array(),
array(),
'',
array(),
array('GET', 'HEAD')
));
$headMatchCasesCollection->add('post_and_head', new Route(