Browse Source

Merge pull request #11474 from saeideng/router-multi-method

accept array of "_method"s  on route::match()
Mark Story 8 years ago
parent
commit
fbd230b1ff
2 changed files with 13 additions and 3 deletions
  1. 6 3
      src/Routing/Route/Route.php
  2. 7 0
      tests/TestCase/Routing/Route/RouteTest.php

+ 6 - 3
src/Routing/Route/Route.php

@@ -741,11 +741,14 @@ class Route
         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;
     }
 
     /**

+ 7 - 0
tests/TestCase/Routing/Route/RouteTest.php

@@ -1199,6 +1199,13 @@ class RouteTest extends TestCase
             '_method' => 'POST',
         ];
         $this->assertEquals('/sample', $route->match($url));
+
+        $url = [
+            'controller' => 'posts',
+            'action' => 'index',
+            '_method' => ['PUT', 'POST'],
+        ];
+        $this->assertEquals('/sample', $route->match($url));
     }
 
     /**