-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tom Wright <tom@inflatablecookie.com>
- Loading branch information
1 parent
00944a4
commit 5a933ff
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
* Added dev OverrideMethod middleware | ||
|
||
## v0.2.15 (2023-12-11) | ||
* Fixed Dispatcher add() signature | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/** | ||
* @package Harvest | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Harvest\Middleware; | ||
|
||
use DecodeLabs\Genesis; | ||
use DecodeLabs\Harvest\PriorityProvider; | ||
use Psr\Http\Message\ResponseInterface as Response; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Psr\Http\Server\MiddlewareInterface as Middleware; | ||
use Psr\Http\Server\RequestHandlerInterface as Handler; | ||
|
||
class OverrideMethod implements | ||
Middleware, | ||
PriorityProvider | ||
{ | ||
/** | ||
* Get default priority | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return -1; | ||
} | ||
|
||
/** | ||
* Process middleware | ||
*/ | ||
public function process( | ||
Request $request, | ||
Handler $next | ||
): Response { | ||
if (class_exists(Genesis::class)) { | ||
$development = Genesis::$environment->isDevelopment(); | ||
} else { | ||
$development = true; | ||
} | ||
|
||
|
||
if ( | ||
$development && | ||
($method = ($request->getQueryParams()['method'] ?? null)) !== null | ||
) { | ||
$request = $request->withMethod($method); | ||
} | ||
|
||
|
||
return $next->handle($request); | ||
} | ||
} |