-
Notifications
You must be signed in to change notification settings - Fork 57
Update to http-middleware 0.4.1 #96
Update to http-middleware 0.4.1 #96
Conversation
- Changed import statements to reflect new namespace, class names. - Removed functionality in `Next` around validating a server request is received; no longer required with changes to http-middleware. - Removed validation of client-side middleware; no longer relevant with changes to http-middleware.
Pinging @michaelmoussa and @xtreamwayz for review as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering why you choose to alias Interop\Http\ServerMiddleware\MiddlewareInterface
as InteropMiddlewareInterface
in src
. In the tests ServerMiddlewareInterface
is being used.
Why not use ServerMiddlewareInterface
for both and keep it consistent? If you choose InteropMiddlewareInterface
you might want to change it again once the PSR is accepted. ServerMiddlewareInterface
could always be used and tells exactly what it is.
That's a good catch. The main reason I chose the verbiage "Interop" was to point out that it's from the http-interop project. That said, once this is ratified by php-fig, we'll be implementing both http-interop (which will be deprecated at that point) and the FIG interfaces — which do not include the "interop" verbiage. As such, I agree with you that the naming needs to change, and will push an update momentarily. |
Pretty straightforward, looks 👍 to me BUT, depending on how optimistic you are about finalization of the FIG interfaces, I'd be inclined to target 2.0.0 for this. Breaking changes are breaking changes. If timing works out we might even manage to lump in the updating of dependencies for the other Expressive components that had major version bumps recently too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I hate having version inflation, but you're absolutely correct. This means, of course, that if there are any breaking changes to http-middleware between now and acceptance, we'll need a v3, but that also provides end-users with a better path forward. I'm thinking with that, we'll also likely want to make Expressive's next version 2.0. We can provide migration tooling to help end-users adapt their existing, callable middleware into http-middleware-compatible middleware, and likely do that at the application level. (We already have some tools in place for this anyways.) Users would then be able to opt-in to the upgrade. I'll get started today and merging in the other breaking changes from the dev-2.0.0 branch into this PR and/or re-target this PR against that branch. |
…ddleware-0.4.1 Conflicts: CHANGELOG.md composer.lock src/Dispatch.php src/Middleware/ErrorHandler.php src/Middleware/NotFoundHandler.php src/MiddlewarePipe.php src/Next.php src/Route.php test/DispatchTest.php test/Middleware/CallableInteropMiddlewareWrapperTest.php test/Middleware/CallableMiddlewareWrapperTest.php test/Middleware/ErrorHandlerTest.php test/Middleware/NotFoundHandlerTest.php test/MiddlewarePipeTest.php test/NextTest.php
ab7e173
to
c718caa
Compare
Use `ServerMiddlewareInterface` throughout project.
* @throws Exception\InvalidMiddlewareException if the $handler provided is | ||
* not an http-interop middleare type. | ||
* not an http-interop middleware type. | ||
*/ | ||
public function __construct($path, $handler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking I can use a typehint here instead of doing the checking within the body; however, doing so affects a ton of tests. I'll see how much work it is.
* @license https://framework.zend.com/license New BSD License | ||
*/ | ||
|
||
namespace ZendTest\Stratigility; | ||
|
||
use Interop\Http\Middleware\DelegateInterface; | ||
use Interop\Http\Middleware\ServerMiddlewareInterface; | ||
use PHPUnit\Framework\TestCase; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware namespacing was a thing in PHPUnit... I'll get all of these reverted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought namespacing was added in version 6. But it seems there is a forward compatibility layer since version 5.4.
- 5.* series has namespaced variants.
Adds the typehint `ServerMiddlewareInterface` to the `$handler` argument of `Route`'s constructor, and removes the internal type verification as it's now redundant.
use Interop\Http\Middleware\DelegateInterface; | ||
use Interop\Http\Middleware\ServerMiddlewareInterface; | ||
use Interop\Http\ServerMiddleware\DelegateInterface; | ||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface; | ||
use PHPUnit_Framework_Assert as Assert; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a PHPUnit\Framework\Assert namespace.
Edit: Since version 5.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome; thanks. Updated!
- requires minimum 5.7 version of PHPUnit.
- Reference http-interop/http-middleware or http-middleware.
can be a `Next` instance, as it also implements that interface. | ||
Starting in version 1.3.0, `MiddlewarePipe` implements the | ||
http-interop/http-middleware server-side middleware interface, and thus provides | ||
a `process()` method. This method requires a `ServerRequestInterface` instance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not specifying the interface name here, as it varies based on the http-middleware version; however, the semantics are the same.
Starting in version 1.3.0, `MiddlewarePipe` implements the | ||
http-interop/http-middleware server-side middleware interface, and thus provides | ||
a `process()` method. This method requires a `ServerRequestInterface` instance | ||
and an http-interop/http-middleware `DelegateInterface` instance on invocation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not specifying the full namespace here, as the namespace varies based on the http-middleware version. The interface name remains the same between the two versions, however, allowing calling it out by its name minus the namespace.
@@ -175,8 +175,6 @@ you will need to: | |||
### Providing an altered request: | |||
|
|||
```php | |||
use Interop\Http\Middleware\DelegateInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the import statements throughout, as they'll vary based on which version of Stratigility, and thus http-middleware, you use. The interface name remains the same between versions.
middleware. Internally, if a response prototype is composed in the | ||
`MiddlewarePipe`, callable middleware piped to the `MiddlewarePipe` will be | ||
Starting in version 1.3.0, we offer the ability to work with | ||
http-interop/http-middleware. Internally, if a response prototype is composed in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started using the verbiage "http-interop/http-middleware" throughout. I'm not sure if I got all of them, but I'm trying to be consistent, as the http-interop project also covers PSR-17 (factories), and may cover client-side middleware in the future.
|
||
// http-interop/http-middleware 0.4.1: | ||
use Interop\Http\ServerMiddleware\DelegateInterface; | ||
use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one place I provided commentary on the different versions, because it's a full example.
|
||
- The namespace changes from `Interop\Http\Middleware` to | ||
`Interop\Http\ServerMiddleware`, signaling a change indicating that the project | ||
now only targests server-side middleware. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targets
Also edited existing changelog entries to prevent confusion about what was finally done. Several were referencing changes that targeted http-middleware 0.2.0, and/or previous iterations in the develop branch that no longer have relevance or have different relevance at this time.
http-interop/http-middleware 0.4.1 is the latest revision, and likely the version that will be used during the FIG review period. It makes the following changes:
Interop\Http\Middleware
toInterop\Http\ServerMiddleware
, to indicate that the specification is only dealing with server-side middleware.ServerMiddlewareInterface
is renamed toMiddlewareInterface
, as the namespace change makes it clear what type of middleware is being defined.DelegateInterface::process
now accepts specifically aServerRequestInterface
instead of a more generalRequestInterface
.Updating to these changes means the following breaking changes:
Next::process()
now typehints againstServerRequestInterface
.The above result in a few breaking changes in the develop branch:
Zend\Stratigility\Next
andZend\Stratigility\Delegate\CallableDelegateDecorator::process
have changed signatures, due to the changes toDelegateInterface::process
; if developers were extending these previously, their code now breaks.I'm currently targeting this at a 1.4.0 release; however, due to the breaking changes, I could target it at a 2.0.0 release. If consensus is to take this latter route, I'll update this repository to merge in the changes currently in the develop branch as well.This targets develop, which is the 2.0.0 feature branch at this time.