Skip to content

Commit

Permalink
accept array of "_method"s on route::match()
Browse files Browse the repository at this point in the history
  • Loading branch information
saeideng committed Nov 28, 2017
1 parent c159efc commit 53b71ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Routing/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,14 @@ protected function _matchMethod($url)
if (empty($url['_method'])) {
return false;
}
if (!in_array(strtoupper($url['_method']), (array)$this->defaults['_method'])) {
return false;
$methods = array_map('strtoupper', (array)$url['_method']);
foreach ($methods as $value) {
if (in_array($value, (array)$this->defaults['_method'])) {
return true;
}
}

return true;
return false;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/TestCase/Routing/Route/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,13 @@ public function testMatchWithMultipleHttpMethodConditions()
'_method' => 'POST',
];
$this->assertEquals('/sample', $route->match($url));

$url = [
'controller' => 'posts',
'action' => 'index',
'_method' => ['PUT', 'POST'],
];
$this->assertEquals('/sample', $route->match($url));
}

/**
Expand Down

0 comments on commit 53b71ce

Please sign in to comment.