Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/145-psr-15-final' into release-3.0.0
Browse files Browse the repository at this point in the history
Close #145
  • Loading branch information
weierophinney committed Jan 23, 2018
2 parents 474ae1e + ef037fe commit d0639c4
Show file tree
Hide file tree
Showing 32 changed files with 94 additions and 224 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,20 @@ details.

### Changed

- [#145](https://github.com/zendframework/zend-stratigility/pull/145) updates
the component to implement and consume **ONLY** PSR-15 interfaces;
http-interop interfaces and callable middleware are no longer directly
supported (though Stratigility provides decorators for the latter in order to
cast them to PSR-15 implementations).

- [#134](https://github.com/zendframework/zend-stratigility/pull/134) marks the
`MiddlewarePipe` class as `final`, disallowing direct extension. Either
compose an instance, or create a custom PSR-15 `MiddlewareInterface`
implementation.

- [#134](https://github.com/zendframework/zend-stratigility/pull/134) updates
`MiddlewarePipe` to implement `Interop\Http\Server\RequestHandlerInterface`.
- [#134](https://github.com/zendframework/zend-stratigility/pull/134) and
[#145](https://github.com/zendframework/zend-stratigility/pull/145) update
`MiddlewarePipe` to implement `Psr\Http\Server\RequestHandlerInterface`.
Calling it will cause it to pull the first middleware off the queue and create
a `Next` implementation that uses the remaining queue as the request handler;
it then processes the middleware.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"keywords": [
"http",
"psr-7",
"psr-15",
"middleware",
"zf",
"zendframework"
Expand All @@ -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": {
Expand Down
114 changes: 1 addition & 113 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions docs/book/v3/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
{
Expand All @@ -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.

Expand All @@ -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
Expand Down Expand Up @@ -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
```

Expand Down
6 changes: 3 additions & 3 deletions docs/book/v3/creating-middleware.md
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
8 changes: 4 additions & 4 deletions docs/book/v3/error-handlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions docs/book/v3/executing-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/book/v3/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 9 additions & 35 deletions docs/book/v3/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
> middleware.
Middleware can decide more processing can be performed by calling the `$handler`
instance passed during invocation. With this paradigm, you can build a workflow
Expand Down Expand Up @@ -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`.
10 changes: 5 additions & 5 deletions docs/book/v3/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit d0639c4

Please sign in to comment.