From c1e0368ff31de41212438629e9642e764b2f8b39 Mon Sep 17 00:00:00 2001 From: Witold Wasiczko Date: Wed, 24 May 2017 13:15:42 +0200 Subject: [PATCH] Add psr-15 support --- README.md | 2 +- composer.json | 8 ++++++-- src/HttpMethodOverrideMiddleware.php | 21 +++++++++------------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3c68e49..6307910 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,6 @@ Use [Expressive Configuration Manager](https://github.com/mtymek/expressive-conf After this you can enable middleware in your middleware-stack using `RstGroup\HttpMethodOverride\HttpMethodOverrideMiddleware` service name in your container. -### Specific installation for Zend Framework 2 +### Specific installation for Zend Framework 2 & 3 Add module `RstGroup\HttpMethodOverride` to `application.config.php` file. diff --git a/composer.json b/composer.json index 5fc1469..138d656 100644 --- a/composer.json +++ b/composer.json @@ -21,14 +21,18 @@ "zendframework/zend-eventmanager": "^2.4 || ^3.0", "zendframework/zend-mvc": "^2.4 || ^3.0", "zendframework/zend-diactoros": "^1.3.3", - "zendframework/zend-modulemanager": "^2.4" + "zendframework/zend-modulemanager": "^2.4", + "php-middleware/double-pass-compatibility": "^1.0", + "http-interop/http-middleware": "^0.4.1" }, "suggest": { "zendframework/zend-http": "To use rstgroup/http-method-override as ZF module", "zendframework/zend-eventmanager": "To use rstgroup/http-method-override as ZF module", "zendframework/zend-mvc": "To use rstgroup/http-method-override as ZF module", "zendframework/zend-modulemanager": "To use rstgroup/http-method-override as ZF module", - "psr/http-message": "To use rstgroup/http-method-override as middleware" + "psr/http-message": "To use rstgroup/http-method-override as middleware", + "php-middleware/double-pass-compatibility": "To use rstgroup/http-method-override as middleware", + "http-interop/http-middleware": "To use rstgroup/http-method-override as middleware" }, "autoload": { "psr-4": { diff --git a/src/HttpMethodOverrideMiddleware.php b/src/HttpMethodOverrideMiddleware.php index 7c21974..ee8b651 100644 --- a/src/HttpMethodOverrideMiddleware.php +++ b/src/HttpMethodOverrideMiddleware.php @@ -2,11 +2,15 @@ namespace RstGroup\HttpMethodOverride; -use Psr\Http\Message\ResponseInterface; +use Interop\Http\ServerMiddleware\DelegateInterface; +use Interop\Http\ServerMiddleware\MiddlewareInterface; +use PhpMiddleware\DoublePassCompatibilityTrait; use Psr\Http\Message\ServerRequestInterface; -final class HttpMethodOverrideMiddleware +final class HttpMethodOverrideMiddleware implements MiddlewareInterface { + use DoublePassCompatibilityTrait; + private $service; public function __construct(HttpMethodOverrideService $service) @@ -14,14 +18,7 @@ public function __construct(HttpMethodOverrideService $service) $this->service = $service; } - /** - * @param ServerRequestInterface $request - * @param ResponseInterface $response - * @param callable $next - * - * @return $response - */ - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) + public function process(ServerRequestInterface $request, DelegateInterface $delegate) { $method = $request->getMethod(); $headers = $this->getHeadersFromRequest($request); @@ -32,7 +29,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res $request = $request->withMethod($overridedHeader); } - return $next($request, $response); + return $delegate->process($request); } /** @@ -51,4 +48,4 @@ private function getHeadersFromRequest(ServerRequestInterface $request) } return $headerNames; } -} \ No newline at end of file +}