Skip to content

Commit

Permalink
Added dev OverrideMethod middleware
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <tom@inflatablecookie.com>
  • Loading branch information
betterthanclay committed Dec 12, 2023
1 parent 00944a4 commit 5a933ff
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
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

Expand Down
55 changes: 55 additions & 0 deletions src/Middleware/OverrideMethod.php
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);
}
}

0 comments on commit 5a933ff

Please sign in to comment.