Skip to content

Commit 0ebfa87

Browse files
authored
Merge pull request dingo#1057 from jakubkratina/master
Only GET | HEAD method for every route fix
2 parents b09482e + 1b4f289 commit 0ebfa87

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Routing/Adapter/Lumen.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function getRouteProperties($route, Request $request)
133133
$methods = isset($route['methods']) ? $route['methods'] : (array) $request->getMethod();
134134
$action = (isset($route[1]) && is_array($route[1])) ? $route[1] : $route;
135135

136-
if ($request->getMethod() === 'GET' && ! in_array('HEAD', $methods)) {
136+
if (in_array('GET', $methods) && ! in_array('HEAD', $methods)) {
137137
$methods[] = 'HEAD';
138138
}
139139

@@ -269,6 +269,8 @@ public function getIterableRoutes($version = null)
269269
}
270270

271271
foreach ($routes as $route) {
272+
$route['methods'] = $this->setRouteMethods($route, $method);
273+
272274
$iterable[$version][] = $route;
273275
}
274276
}
@@ -281,6 +283,8 @@ public function getIterableRoutes($version = null)
281283

282284
foreach ($routes as $data) {
283285
foreach ($data['routeMap'] as list($route, $parameters)) {
286+
$route['methods'] = $this->setRouteMethods($route, $method);
287+
284288
$iterable[$version][] = $route;
285289
}
286290
}
@@ -371,4 +375,19 @@ public function gatherRouteMiddlewares($route)
371375
// Route middleware in Lumen is not terminated.
372376
return [];
373377
}
378+
379+
/**
380+
* Append given method to the current route methods.
381+
*
382+
* @param array $route
383+
* @param string $method
384+
*
385+
* @return array
386+
*/
387+
private function setRouteMethods($route, $method)
388+
{
389+
return isset($route['methods'])
390+
? array_push($route['methods'], $method)
391+
: [$method];
392+
}
374393
}

0 commit comments

Comments
 (0)