From b9d910594823bd17f0477f539f0bf7169a977fc7 Mon Sep 17 00:00:00 2001 From: webimpress Date: Tue, 23 Jan 2018 14:45:50 +0000 Subject: [PATCH] Updated to final PSR-15 --- composer.json | 3 +- composer.lock | 114 +----------------- docs/book/v3/api.md | 12 +- docs/book/v3/creating-middleware.md | 6 +- docs/book/v3/error-handlers.md | 8 +- docs/book/v3/executing-middleware.md | 6 +- docs/book/v3/install.md | 5 +- docs/book/v3/middleware.md | 44 ++----- docs/book/v3/migration.md | 10 +- .../CallableMiddlewareDecorator.php | 6 +- .../DoublePassMiddlewareDecorator.php | 6 +- src/Middleware/ErrorHandler.php | 4 +- src/Middleware/HostMiddlewareDecorator.php | 4 +- src/Middleware/NotFoundHandler.php | 6 +- src/Middleware/OriginalMessages.php | 6 +- src/Middleware/PathMiddlewareDecorator.php | 5 +- src/MiddlewarePipe.php | 6 +- src/Next.php | 4 +- src/functions/host.php | 2 +- src/functions/path.php | 2 +- .../CallableMiddlewareDecoratorTest.php | 4 +- .../DoublePassMiddlewareDecoratorTest.php | 4 +- test/Middleware/ErrorHandlerTest.php | 4 +- .../HostMiddlewareDecoratorTest.php | 4 +- test/Middleware/NotFoundHandlerTest.php | 4 +- test/Middleware/OriginalMessagesTest.php | 4 +- ...PathMiddlewareDecoratorIntegrationTest.php | 4 +- .../PathMiddlewareDecoratorTest.php | 4 +- test/MiddlewarePipeTest.php | 6 +- test/MiddlewareTrait.php | 4 +- test/NextTest.php | 6 +- 31 files changed, 85 insertions(+), 222 deletions(-) diff --git a/composer.json b/composer.json index 46f9a68..791624c 100644 --- a/composer.json +++ b/composer.json @@ -5,6 +5,7 @@ "keywords": [ "http", "psr-7", + "psr-15", "middleware", "zf", "zendframework" @@ -19,8 +20,8 @@ }, "require": { "php": "^7.1", - "http-interop/http-server-middleware": "^1.1.1", "psr/http-message": "^1.0", + "psr/http-server-middleware": "^1.0", "zendframework/zend-escaper": "^2.3" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 8f3d180..b816500 100644 --- a/composer.lock +++ b/composer.lock @@ -4,67 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "77cb3bc077c17d152d51b5d15abcf8b1", + "content-hash": "c8add8be84844b01406c95b4715c929a", "packages": [ - { - "name": "http-interop/http-server-middleware", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/http-interop/http-server-middleware.git", - "reference": "1ed99649e5f0d785c16d53cc021d7187ec350f28" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/http-interop/http-server-middleware/zipball/1ed99649e5f0d785c16d53cc021d7187ec350f28", - "reference": "1ed99649e5f0d785c16d53cc021d7187ec350f28", - "shasum": "" - }, - "require": { - "php": ">=7.0", - "psr/http-message": "^1.0", - "psr/http-server-middleware": "^1.0" - }, - "replace": { - "http-interop/http-middleware": ">=0.5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Interop\\Http\\Server\\": "src/" - }, - "files": [ - "src/alias.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP server-side middleware", - "keywords": [ - "http", - "middleware", - "psr", - "psr-15", - "psr-7", - "request", - "response" - ], - "abandoned": "psr/http-server-middleware", - "time": "2018-01-23T14:34:55+00:00" - }, { "name": "psr/http-message", "version": "1.0.1", @@ -321,59 +262,6 @@ ], "time": "2017-07-22T11:58:36+00:00" }, - { - "name": "http-interop/http-server-handler", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/http-interop/http-server-handler.git", - "reference": "931a6495fb1b6005c9b4abc4dd11fb12a2a8103b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/http-interop/http-server-handler/zipball/931a6495fb1b6005c9b4abc4dd11fb12a2a8103b", - "reference": "931a6495fb1b6005c9b4abc4dd11fb12a2a8103b", - "shasum": "" - }, - "require": { - "php": ">=7.0", - "psr/http-message": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Interop\\Http\\Server\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP server-side request handler", - "keywords": [ - "handler", - "http", - "psr", - "psr-15", - "psr-7", - "request", - "response", - "server" - ], - "abandoned": "psr/http-server-handler", - "time": "2017-11-09T18:35:22+00:00" - }, { "name": "malukenho/docheader", "version": "0.1.7", diff --git a/docs/book/v3/api.md b/docs/book/v3/api.md index e341408..6184acd 100644 --- a/docs/book/v3/api.md +++ b/docs/book/v3/api.md @@ -7,7 +7,7 @@ The following make up the primary API of Stratigility. > - Affects: version 3.0.0alpha1 > > Starting with version 3.0.0, support for http-interop/http-middleware has been -> replaced with support for http-interop/http-server-middleware. +> replaced with support for psr/http-server-middleware. ## Middleware @@ -17,10 +17,10 @@ has been discussed previously. Its API is: ```php namespace Zend\Stratigility; -use Interop\Http\Server\MiddlewareInterface; -use Interop\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; class MiddlewarePipe implements MiddlewareInterface, RequestHandlerInterface { @@ -39,7 +39,7 @@ Middleware is executed in the order in which it is piped to the `MiddlewarePipe` instance. The `MiddlewarePipe` is itself middleware, and can be executed in stacks that -expect http-interop middleware signatures. It is also a request handler, +expect PSR-15 middleware signatures. It is also a request handler, allowing you to use it in paradigms where a request handler is required; when executed in this way, it will process itself in order to generate a response. @@ -58,7 +58,7 @@ returned. `Zend\Stratigility\Next` is primarily an implementation detail, and exists to allow delegating to middleware aggregated in the `MiddlewarePipe`. It is -implemented as an http-interop/http-middleware `RequestHandlerInterface`. +implemented as an PSR-15 `RequestHandlerInterface`. Since your middleware needs to return a response, the instance receives the `$handler` argument passed to `MiddlewarePipe::process()` as a fallback request @@ -265,7 +265,7 @@ $pipeline->pipe(host('example.com', $middleware)); ```php function Zend\Stratigility\path( string $pathPrefix, - Interop\Http\Server\MiddlewareInterface $middleware + Psr\Http\Server\MiddlewareInterface $middleware ) : Zend\Stratigility\Middleware\PathMiddlewareDecorator ``` diff --git a/docs/book/v3/creating-middleware.md b/docs/book/v3/creating-middleware.md index eadd2b7..168c52f 100644 --- a/docs/book/v3/creating-middleware.md +++ b/docs/book/v3/creating-middleware.md @@ -1,13 +1,13 @@ # Creating Middleware Middleware piped to a `MiddlewarePipe` **MUST** implement the -http-interop/http-server-middleware interface. +PSR-15 middleware interface. ```php -use Interop\Http\Server\MiddlewareInterface; -use Interop\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; class MyMiddleware implements MiddlewareInterface { diff --git a/docs/book/v3/error-handlers.md b/docs/book/v3/error-handlers.md index f8cd6f4..bad4e68 100644 --- a/docs/book/v3/error-handlers.md +++ b/docs/book/v3/error-handlers.md @@ -34,12 +34,12 @@ If you would like a templated response, you will need to write your own middleware; such middleware might look like the following: ```php -use Interop\Http\ServerMiddleware\DelegateInterface; -use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; -class NotFoundMiddleware implements ServerMiddlewareInterface +class NotFoundMiddleware implements MiddlewareInterface { private $renderer; @@ -51,7 +51,7 @@ class NotFoundMiddleware implements ServerMiddlewareInterface $this->response = $response; } - public function process(ServerRequestInterface $request, DelegateInterface $delegate) + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) { $response = $this->response->withStatus(404); $response->getBody()->write( diff --git a/docs/book/v3/executing-middleware.md b/docs/book/v3/executing-middleware.md index 97db0e4..b6dc84c 100644 --- a/docs/book/v3/executing-middleware.md +++ b/docs/book/v3/executing-middleware.md @@ -42,7 +42,7 @@ You can learn how to customize the error handler to your needs in the ## Decorating the MiddlewarePipe Another approach is to compose a `Zend\Stratigility\MiddlewarePipe` instance -within your own `Interop\Http\Server\MiddlewareInterface` implementation, and +within your own `Psr\Http\Server\MiddlewareInterface` implementation, and optionally implementing the `RequestHandlerInterface` and/or `pipe()` method. In such a case, you might define the `process()` method to perform any @@ -75,10 +75,10 @@ Another approach using this method would be to override the constructor to add in specific middleware, perhaps using configuration provided. ```php -use Interop\Http\Server\MiddlewareInterface; -use Interop\Http\Server\RequestHandlerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; use Zend\Stratigility\MiddlewarePipe; class CustomMiddleware implements MiddlewareInterface diff --git a/docs/book/v3/install.md b/docs/book/v3/install.md index 174c21a..0d2aec5 100644 --- a/docs/book/v3/install.md +++ b/docs/book/v3/install.md @@ -14,8 +14,9 @@ Stratigility has the following dependencies (which are managed by Composer): will need an implementation of PSR-7; one such package is [Diactoros](https://docs.zendframework.com/zend-diactoros/). -- [http-interop/http-server-middleware](https://github.com/http-interop/http-server-middleware), - which provides the interfaces that will become PSR-15. +- [psr/http-server-middleware](https://github.com/php-fig/http-server-middleware), + which provides the [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) + interfaces. - `zendframework/zend-escaper`, used by the `ErrorHandler` middleware and the (legacy) `FinalHandler` implementation for escaping error messages prior to diff --git a/docs/book/v3/middleware.md b/docs/book/v3/middleware.md index 53b835a..100a392 100644 --- a/docs/book/v3/middleware.md +++ b/docs/book/v3/middleware.md @@ -7,11 +7,12 @@ take the incoming request, perform actions based on it, and either complete the response or pass delegation on to the next middleware in the queue. ```php -use Interop\Http\Server\MiddlewareInterface; -use Interop\Http\Server\RequestHandlerInterface; +use Psr\Http\Server\MiddlewareInterface; +use Psr\Http\Server\RequestHandlerInterface; use Zend\Diactoros\Response; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; + use function Zend\Stratigility\middleware; use function Zend\Stratigility\path; @@ -59,37 +60,10 @@ So, concisely put, _middleware are PHP callables that accept a request object, and do something with it, optionally delegating creation of a response to another handler_. -> ### http-interop middleware -> -> The above example demonstrates the using the interfaces from the http-interop -> project. http-interop is a project attempting to standardize middleware signatures. -> The signature of the http-interop/http-server-middleware 1.0 series, on which -> Stratigility 3.X is based, is: -> -> ```php -> namespace Interop\Http\Server; -> -> use Psr\Http\Message\ResponseInterface; -> use Psr\Http\Message\ServerRequestInterface; -> -> interface MiddlewareInterface -> { -> public function process( -> ServerRequestInterface $request, -> RequestHandlerInterface $handler -> ) : ResponseInterface; -> } -> -> interface RequestHandlerInterface -> { -> public function process( -> ServerRequestInterface $request -> ) : ResponseInterface; -> } -> ``` +> ### PSR-15 middleware > -> Stratigility allows you to implement the http-interop/http-server-middleware -> interface to provide middleware. +> Stratigility supports only [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) +> middlewares. Middleware can decide more processing can be performed by calling the `$handler` instance passed during invocation. With this paradigm, you can build a workflow @@ -119,7 +93,7 @@ The handlers in each middleware attached this way will see a URI with that path segment stripped, allowing them to be developed separately and re-used under any path you wish. -Within Stratigility, middleware can be any -[http-interop/http-server-middleware](https://github.com/http-interop/http-server-middleware). +Within Stratigility, middleware must be +[PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) middleware. `Zend\Stratigility\MiddlewarePipe` implements -`Interop\Http\Server\MiddlewareInterface`. +`Psr\Http\Server\MiddlewareInterface`. diff --git a/docs/book/v3/migration.md b/docs/book/v3/migration.md index 7ff6475..d2f129b 100644 --- a/docs/book/v3/migration.md +++ b/docs/book/v3/migration.md @@ -20,11 +20,11 @@ been dropped. ## PSR-15 -Stratigility now supports only PSR-15 interfaces. Support of -`http-interop/http-middleware` has been dropped. +Stratigility now supports only [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) +interfaces. Support of `http-interop/http-middleware` has been dropped. -All middleware and request handlers must now implement PSR-15 interfaces, -including those Stratigility implements. +All middleware and request handlers must now implement [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) +interfaces, including those Stratigility implements. As a result, a number of signatures have been changed. Primarily, these were a matter of updating typehints on @@ -49,7 +49,7 @@ All of these classes now implement the PSR-15 `MiddlewareInterface`. ## Pipeline - `MiddlewarePipe` -We now only allow piping `Interop\Http\Server\MiddlewareInterface` instances +We now only allow piping `Psr\Http\Server\MiddlewareInterface` instances into the `MiddlewarePipe` class. In version 2, we had a number of internal utilities for identifying other types diff --git a/src/Middleware/CallableMiddlewareDecorator.php b/src/Middleware/CallableMiddlewareDecorator.php index 880b0d6..8e0e98a 100644 --- a/src/Middleware/CallableMiddlewareDecorator.php +++ b/src/Middleware/CallableMiddlewareDecorator.php @@ -1,17 +1,17 @@