Skip to content

Commit

Permalink
Merge branch 'release/v0.2.16'
Browse files Browse the repository at this point in the history
  • Loading branch information
betterthanclay committed Dec 12, 2023
2 parents 1012eb1 + 3be6e2d commit 6602709
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v0.2.16 (2023-12-12)
* 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 6602709

Please sign in to comment.