diff --git a/.travis.yml b/.travis.yml index c710167..bfded4c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.0 - 7.1 before_script: @@ -15,4 +14,4 @@ after_success: - bash <(curl -s https://codecov.io/bash) notifications: - email: false \ No newline at end of file + email: false diff --git a/README.md b/README.md index a5702b4..0f881c1 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,29 @@ # expressive-session-middleware -Session handling middleware based on zend-session for use in zend expressive 2.0 applications. +Session handling middleware based on zend-session for use in zend expressive 3 applications. [![Build Status](https://travis-ci.org/dwendrich/expressive-session-middleware.svg?branch=master)](https://travis-ci.org/dwendrich/expressive-session-middleware) [![Coverage Status](https://img.shields.io/codecov/c/github/dwendrich/expressive-session-middleware.svg?style=flat)](https://codecov.io/gh/dwendrich/expressive-session-middleware) [![Latest Stable Version](http://img.shields.io/packagist/v/dwendrich/expressive-session-middleware.svg?style=flat)](https://packagist.org/packages/dwendrich/expressive-session-middleware) +## PSR-15 Support +This version supports [PSR-15](https://www.php-fig.org/psr/psr-15) instead of http-interop/http-middleware interfaces, +as currently implemented by zend expressive 3. For use with older versions of zend expressive, please refer to version +0.1.9. + ## Requirements -* PHP 7.0 or above +* PHP 7.1 or above * [zendframework/zend-session](https://docs.zendframework.com/zend-session/) ## Installation Install the latest version with composer. For information on how to get composer or how to use it, please refer to [getcomposer.org](http://getcomposer.org). ```sh -$ composer require dwendrich/expressive-soap-middleware +$ composer require dwendrich/expressive-session-middleware ``` If during installation you are prompted to inject `Zend\Session\ConfigProvider` into your configuration, you can simply ignore and continue without it. All relevant configuration is part of `SessionMiddleware\ConfigProvider`. -As part of a zend-expressive 2.0 application add `SessionMiddleware\ConfigProvider::class` to `config/config.php`: +As part of a zend-expressive application add `SessionMiddleware\ConfigProvider::class` to `config/config.php`: ```php $aggregator = new ConfigAggregator([ @@ -49,7 +54,7 @@ You can add the middleware to the file `config/pipeline.php`: $app->pipe(SessionMiddleware::class); // Register the routing middleware in the middleware pipeline -$app->pipeRoutingMiddleware(); +$app->pipe(\Zend\Expressive\Router\Middleware\RouteMiddleware::class); $app->pipe(ImplicitHeadMiddleware::class); $app->pipe(ImplicitOptionsMiddleware::class); $app->pipe(UrlHelperMiddleware::class); @@ -58,7 +63,7 @@ Depending on which middleware should get access to the session, you should prepe Commonly before registering the routing middleware is a good way to go. This way the middleware is invoked on every request to your application. Since session handling may produce some -overhead which isn't always needed there is an alternative. +overhead, which isn't always needed, there is an alternative: #### 2. Add the middleware to a specific route Add a route definition to either `config/routes.php` or a `RouteDelegator` as part of your application: @@ -75,7 +80,7 @@ $app->route( ``` This way session handling is bound to a specific path in your application where it may be needed. -For further information on programmatic pipelines and routing in zend expressive 2.0 please refer to the +For further information on programmatic pipelines and routing in zend expressive please refer to the [documentation](https://docs.zendframework.com/zend-expressive/cookbook/autowiring-routes-and-pipelines/). ## Basic usage @@ -92,7 +97,7 @@ by testing against the request attribute: * * @return ResponseInterface */ -public function process(ServerRequestInterface $request, DelegateInterface $delegate) +public function process(ServerRequestInterface $request, DelegateInterface $delegate) : ResponseInterface { $sessionManager = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE, false); @@ -180,4 +185,4 @@ return [ ], ], ]; -``` \ No newline at end of file +``` diff --git a/composer.json b/composer.json index 278afed..144e4ca 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { "name": "dwendrich/expressive-session-middleware", - "description": "Session handling middleware for use with zend expressive 2.0 based on zend-session.", + "description": "Session handling middleware for use with zend expressive 3 based on zend-session.", "keywords": [ "session handling", - "psr-7", + "psr-15", "zend", "expressive", "middleware" @@ -27,10 +27,11 @@ } }, "require": { - "php": "^7.0", + "php": "^7.1", "zendframework/zend-session": "^2.7", "zendframework/zend-servicemanager": "^3.3", "psr/http-message": "^1.0", + "psr/http-server-middleware": "^1.0", "http-interop/http-middleware": "^0.4.1" }, "require-dev": { diff --git a/src/Middleware/SessionMiddleware.php b/src/Middleware/SessionMiddleware.php index 9c5da13..5d3c603 100644 --- a/src/Middleware/SessionMiddleware.php +++ b/src/Middleware/SessionMiddleware.php @@ -1,9 +1,11 @@ sessionManager->start(); // call next middleware in stack and directly return response - return $delegate->process( + return $delegate->handle( // pass on session manager as request attribute $request->withAttribute(self::SESSION_ATTRIBUTE, $this->sessionManager) ); diff --git a/test/Middleware/SessionMiddlewareTest.php b/test/Middleware/SessionMiddlewareTest.php index e8ba4c6..49c6e39 100644 --- a/test/Middleware/SessionMiddlewareTest.php +++ b/test/Middleware/SessionMiddlewareTest.php @@ -2,7 +2,7 @@ namespace SessionMiddlewareTest\Middleware; -use Interop\Http\ServerMiddleware\DelegateInterface; +use Psr\Http\Server\RequestHandlerInterface as DelegateInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use PHPUnit\Framework\TestCase; @@ -27,7 +27,7 @@ public function testSessionStartIsCalledAndRequestIsDelegated() $response = $this->prophesize(ResponseInterface::class)->reveal(); $delegate = $this->prophesize(DelegateInterface::class); - $delegate->process(Argument::any())->will(function () use(&$invoked, $response) { + $delegate->handle(Argument::any())->will(function () use(&$invoked, $response) { $invoked = true; return $response; }); @@ -47,4 +47,4 @@ public function testSessionStartIsCalledAndRequestIsDelegated() $this->assertSame($response, $return); $this->assertTrue($invoked); } -} \ No newline at end of file +}