-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn decorators into middleware chain
- Loading branch information
Showing
21 changed files
with
194 additions
and
155 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
10 changes: 0 additions & 10 deletions
10
src/Payment/Request/Decorators/RequestDecoratorInterface.php
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
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,37 @@ | ||
<?php | ||
|
||
namespace Mollie\WooCommerce\Payment\Request\Middleware; | ||
|
||
use WC_Order; | ||
|
||
class MiddlewareHandler | ||
{ | ||
private array $middlewares; | ||
|
||
public function __construct(array $middlewares) | ||
{ | ||
$this->middlewares = $middlewares; | ||
} | ||
|
||
public function handle(array $requestData, WC_Order $order, $context = null): array | ||
{ | ||
$middlewareChain = $this->createMiddlewareChain($this->middlewares); | ||
|
||
return $middlewareChain($requestData, $order, $context); | ||
} | ||
|
||
private function createMiddlewareChain(array $middlewares): callable | ||
{ | ||
return array_reduce( | ||
array_reverse($middlewares), | ||
function ($next, $middleware) { | ||
return function ($requestData, $order, $context) use ($middleware, $next) { | ||
return $middleware($requestData, $order, $context, $next); | ||
}; | ||
}, | ||
function ($requestData) { | ||
return $requestData; | ||
} | ||
); | ||
} | ||
} |
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
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
10 changes: 10 additions & 0 deletions
10
src/Payment/Request/Middleware/RequestMiddlewareInterface.php
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,10 @@ | ||
<?php | ||
|
||
namespace Mollie\WooCommerce\Payment\Request\Middleware; | ||
|
||
use WC_Order; | ||
|
||
interface RequestMiddlewareInterface | ||
{ | ||
public function __invoke(array $requestData, WC_Order $order, string $context = null, callable $next): array; | ||
} |
Oops, something went wrong.