mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 04:52:14 +00:00
[BUGFIX] Issue #439: Fixed multiple request-type on same routes.
This commit is contained in:
@@ -262,8 +262,8 @@ class Router
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load routes
|
* Load routes
|
||||||
* @throws NotFoundHttpException
|
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws NotFoundHttpException
|
||||||
*/
|
*/
|
||||||
public function loadRoutes(): void
|
public function loadRoutes(): void
|
||||||
{
|
{
|
||||||
@@ -350,7 +350,7 @@ class Router
|
|||||||
{
|
{
|
||||||
$this->debug('Routing request');
|
$this->debug('Routing request');
|
||||||
|
|
||||||
$methodNotAllowed = false;
|
$methodNotAllowed = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$url = $this->request->getRewriteUrl() ?? $this->request->getUrl()->getPath();
|
$url = $this->request->getRewriteUrl() ?? $this->request->getUrl()->getPath();
|
||||||
@@ -370,7 +370,12 @@ class Router
|
|||||||
/* Check if request method matches */
|
/* Check if request method matches */
|
||||||
if (\count($route->getRequestMethods()) !== 0 && \in_array($this->request->getMethod(), $route->getRequestMethods(), true) === false) {
|
if (\count($route->getRequestMethods()) !== 0 && \in_array($this->request->getMethod(), $route->getRequestMethods(), true) === false) {
|
||||||
$this->debug('Method "%s" not allowed', $this->request->getMethod());
|
$this->debug('Method "%s" not allowed', $this->request->getMethod());
|
||||||
$methodNotAllowed = true;
|
|
||||||
|
// Only set method not allowed is not already set
|
||||||
|
if ($methodNotAllowed === null) {
|
||||||
|
$methodNotAllowed = true;
|
||||||
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,9 +480,9 @@ class Router
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Exception $e
|
* @param \Exception $e
|
||||||
* @throws HttpException
|
|
||||||
* @throws \Exception
|
|
||||||
* @return string|null
|
* @return string|null
|
||||||
|
* @throws \Exception
|
||||||
|
* @throws HttpException
|
||||||
*/
|
*/
|
||||||
protected function handleException(\Exception $e): ?string
|
protected function handleException(\Exception $e): ?string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -210,4 +210,16 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertTrue(true);
|
$this->assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSameRoutes()
|
||||||
|
{
|
||||||
|
|
||||||
|
TestRouter::get('/recipe', 'DummyController@method1')->name('add');
|
||||||
|
TestRouter::post('/recipe', 'DummyController@method2')->name('edit');
|
||||||
|
|
||||||
|
TestRouter::debugNoReset('/recipe', 'post');
|
||||||
|
TestRouter::debug('/recipe', 'get');
|
||||||
|
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user