From 1ead65c4dc0ab16b896b646a147028c4731a1f08 Mon Sep 17 00:00:00 2001 From: Oras Al-Kubaisi Date: Wed, 3 May 2017 11:28:28 +0100 Subject: [PATCH] changed to used Stratigility 2 and to use Interop Http Middleware to be compatible with Zend Expressive 2 --- composer.json | 2 +- src/MonologMiddleware/MonologMiddleware.php | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 4444656..e897517 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "php": "^5.5 || ^7.0", "monolog/monolog": "^1.19", "psr/http-message": "~1.0.0", - "zendframework/zend-stratigility": "^1.2", + "zendframework/zend-stratigility": "^2", "container-interop/container-interop": "^1.1", "symfony/http-foundation": "^3.0", "guzzlehttp/psr7": "^1.3 || ^1.4" diff --git a/src/MonologMiddleware/MonologMiddleware.php b/src/MonologMiddleware/MonologMiddleware.php index 2529d65..30a4d84 100644 --- a/src/MonologMiddleware/MonologMiddleware.php +++ b/src/MonologMiddleware/MonologMiddleware.php @@ -2,13 +2,14 @@ namespace MonologMiddleware; +use Interop\Http\ServerMiddleware\DelegateInterface; +use Interop\Http\ServerMiddleware\MiddlewareInterface; use Monolog\Logger; use MonologMiddleware\Loggable\LoggableData; use MonologMiddleware\Loggable\LoggableProvider; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Symfony\Component\HttpFoundation\Response; -use Zend\Stratigility\MiddlewareInterface; /** * Class MonologMiddleware @@ -36,21 +37,14 @@ public function __construct(Logger $logger, loggableProvider $loggableProvider) $this->loggableProvider = $loggableProvider; } - - /** - * @param ServerRequestInterface $request - * @param ResponseInterface $response - * @param callable $next - * @return mixed - */ - public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) + public function process(ServerRequestInterface $request, DelegateInterface $delegate) { - $nextResponse = $next($request, $response); + $response = $delegate->process($request); $level = $this->getLogLevel($response->getStatusCode()); - $this->log($level, $request, $nextResponse); + $this->log($level, $request, $response); - return $nextResponse; + return $response; } /** @@ -83,10 +77,11 @@ public function getLogLevel($responseCode) return $level; } + /** * @param $level * @param ServerRequestInterface $request - * @param Response $response + * @param ResponseInterface $response * @return bool */ public function log($level, ServerRequestInterface $request, ResponseInterface $response)