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

Add webimpress/http-middleware-compatibility support #260

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ All notable changes to this project will be documented in this file, in reverse

### Added

- Nothing.
- [#260](https://github.com/zendframework/zend-mvc/pull/260) adds support for
http-interop/http-middleware 0.5.0 via a polyfill provided by the package
webimpress/http-middleware-compatibility. This in turn adds full support for
zend-stratigility ^2.1

### Deprecated

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"zendframework/zend-coding-standard": "~1.0.0",
"zendframework/zend-json": "^2.6.1 || ^3.0",
"zendframework/zend-psr7bridge": "^0.2",
"zendframework/zend-stratigility": "^2.0.1"
"zendframework/zend-stratigility": "^2.1"
},
"suggest": {
"zendframework/zend-json": "(^2.6.1 || ^3.0) To auto-deserialize JSON body content in AbstractRestfulController extensions, when json_decode is unavailable",
Expand All @@ -42,7 +42,7 @@
"zendframework/zend-paginator": "^2.7 To provide pagination functionality via PaginatorPluginManager",
"zendframework/zend-psr7bridge": "(^0.2) To consume PSR-7 middleware within the MVC workflow",
"zendframework/zend-servicemanager-di": "zend-servicemanager-di provides utilities for integrating zend-di and zend-servicemanager in your zend-mvc application",
"zendframework/zend-stratigility": "zend-stratigility is required to use middleware pipes in the MiddlewareListener"
"zendframework/zend-stratigility": "^2.1 zend-stratigility is required to use middleware pipes in the MiddlewareListener"
},
"config": {
"sort-packages": true
Expand Down
128 changes: 110 additions & 18 deletions composer.lock

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

8 changes: 6 additions & 2 deletions src/MiddlewareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as PsrServerRequestInterface;
use Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface as CompatMiddleware;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\Controller\MiddlewareController;
use Zend\Mvc\Exception\InvalidMiddlewareException;
use Zend\Mvc\Exception\ReachedFinalHandlerException;
use Zend\Mvc\Controller\MiddlewareController;
use Zend\Psr7Bridge\Psr7Response;
use Zend\Router\RouteMatch;
use Zend\Stratigility\Delegate\CallableDelegateDecorator;
Expand Down Expand Up @@ -142,7 +143,10 @@ private function createPipeFromSpec(
if (is_string($middlewareToBePiped) && $serviceLocator->has($middlewareToBePiped)) {
$middlewareToBePiped = $serviceLocator->get($middlewareToBePiped);
}
if (! $middlewareToBePiped instanceof MiddlewareInterface && ! is_callable($middlewareToBePiped)) {
if (! $middlewareToBePiped instanceof MiddlewareInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this line anymore, please check line 11 in this file:

use Interop\Http\ServerMiddleware\MiddlewareInterface;

it should be removed.

You are using MiddlewareInstance from webimpress/http-middleware-compatibility so it's enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed for stratigility 2.0.x

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xerkus ok, fine, but we are not testing it then... Maybe we should set requirements to ^2.0.1 as it was and write additional test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Xerkus I've added tests in #262

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really supporting it any more but allowing it to be used anyway as it is an optional dependency. If it was direct dependency, I would have bumped it to ^2.1.x and dropped that check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we keep this condition here, it should be also tested, this is why I've added it in PR #262 :)

&& ! $middlewareToBePiped instanceof CompatMiddleware
&& ! is_callable($middlewareToBePiped)
) {
throw InvalidMiddlewareException::fromMiddlewareName($middlewareName);
}

Expand Down
2 changes: 1 addition & 1 deletion test/MiddlewareListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace ZendTest\Mvc;

use Interop\Container\ContainerInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Webimpress\HttpMiddlewareCompatibility\MiddlewareInterface;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down