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

Added support for http-interop/http-middleware 0.5.0 (No BC Break) #46

Merged
merged 1 commit into from
Oct 9, 2017
Merged

Added support for http-interop/http-middleware 0.5.0 (No BC Break) #46

merged 1 commit into from
Oct 9, 2017

Conversation

michalbundyra
Copy link
Member

@michalbundyra michalbundyra commented Oct 5, 2017

We keep also support for previosu version. It is accomplished by webimpress/http-middleware-compatibility repository, which allow to use any version of http-middleware. Consumer of the library can decide what version of http-middleware to use, and can easily migrate to the latest version at any time.

Requires zendframework/zend-expressive-router#36 to be merged before and released. Then composer.json in this PR should be updated.

@michalbundyra
Copy link
Member Author

I've left composer.lock with http-middleware version 0.4.1 so tests run with:

  • lowest - 0.1.1
  • locked - 0.4.1
  • latest - 0.5.0

Copy link

@zf2timo zf2timo left a comment

Choose a reason for hiding this comment

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

Generally I do not see a benefit from this change. A central method of this Project is defined in another project and that's lead to increased complexity.

"repositories": [
{
"type": "git",
"url": "https://github.com/webimpress/zend-expressive-router.git"
Copy link

Choose a reason for hiding this comment

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

Why is this package not published on packagist.org?

Copy link
Member Author

Choose a reason for hiding this comment

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

@zf2timo This PR requires another one to be merged before - zendframework/zend-expressive-router#36
After merge PR in expressive-router, this PR will be updated.

@@ -77,7 +79,7 @@ public function clearStrategies()
public function process(ServerRequestInterface $request, DelegateInterface $delegate)
{
if (in_array($request->getMethod(), $this->nonBodyRequests)) {
return $delegate->process($request);
return $delegate->{HANDLER_METHOD}($request);
Copy link

Choose a reason for hiding this comment

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

Why is this changed? It increases the complexity and I think it has an negative impact on the performance.

Copy link
Member Author

Choose a reason for hiding this comment

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

The purpose of this PR is to provide Non-BC-Break change to support http-interop/http-middleware in version 0.4.1 and 0.5.0. We accomplish it by using separate repository - webimpress/http-middleware-compatibility. Now consumer of the library can decide what version of http-interop middleware to use. Please note that handler/delegator interface has been changed in 0.5.0 release and this is the simplest way (I can see right now) to provide that functionality.

Please see webimpress/http-middleware-compatibility library for more information.

Copy link

Choose a reason for hiding this comment

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

Okay, I can see your intend now. But does it really need a solution like this? The http-interop is not a stable release yet. So it could be possible that not only the name of the method changes, but also the signature changes. These changes can not be covered by your solution.
The signature changes can only be handled by a wrapper module - which is my preferred solution, because you do not have the "magic" with {HANDLER_METHOD}($request) .

Copy link
Member Author

Choose a reason for hiding this comment

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

@zf2timo Please note that signature has been changed (of middleware) and interfaces has different namespace. I covered it all in my library. This "magic" trick with method name is the simples solution what I can think of right now, and probably it will work until we have a final PSR-15.
Of course wrapper will be better, but unfortunately wrapper is going to provide BC break. We would rather avoid this right now, but we don't want stop users of using the latest version of http-interop middleware. With that solution you can use any version. This is temporary solution, the final one will be when PSR-15 is released.

I wouldn't be worried about performance. We define the constant only on autoloading. Other than that we just using aliases also defined on autoloading. In your library which consumes that library you can use http-interop directly. Whatever is easier for you. Finally, when PSR-15 will be released you will need to update your application anyway. And using this solution, it's quite possible that you will be able to do before all zend libraries implement that changes 😄

Copy link
Member

Choose a reason for hiding this comment

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

I don't see a likely performance change due to this, TBH. As @webimpress notes, the constant and aliases are defined when the autoloaders are first created, which means in production it will happen the first time the application is hit only, and not on subsequent requests.

Second, regarding this:

it could be possible that not only the name of the method changes, but also the signature changes

While this change from 0.4.1 to 0.5.0 is pretty major, I think this will likely be the last major change we have in the specification. 0.4.1 proved itself quite well; 0.5.0 is mainly around some re-naming to allow usage of the "request handler" (formerly the "delegate") outside the scope of the middleware interface; in terms of how the interfaces relate and work, they are exactly the same.

The main concern I have is that we have to make two changes: one now, to allow for both backwards and forwards compatibility, and another for the next major release, which removes this workaround in favor of the final PSR-15 interfaces. Having to make changes twice, across multiple libraries, is painful and often fragile (we forget the order in which the changes need to be made, or forget which libraries need changes, etc.).

The chief benefit I see to making the change now is that it provides an implementation of the current version of the PSR-15 specification, which will allow it to move forward towards an acceptance vote. As such, I'm weighing in as being in favor of this change at this time.

I've pointed out the library @webimpress has made to other members of the PSR-15 working group, and want to discuss with them briefly before I merge these, to make sure nothing is being missed. If they think it looks reasonable, I'll proceed in merging this and the other related changes.

We keep also support for previous version. It is accomplished by
`webimpress/http-middleware-compatibility` repository, which allow
to use any version of http-middleware. Consumer of the library can
decide what version of http-middleware to use, and can easily migrate
to the latest version at any time.
@michalbundyra michalbundyra changed the base branch from master to develop October 7, 2017 10:00
@michalbundyra
Copy link
Member Author

Rebased and changed target do develop branch.

@weierophinney weierophinney merged commit 3358747 into zendframework:develop Oct 9, 2017
weierophinney added a commit that referenced this pull request Oct 9, 2017
Added support for `http-interop/http-middleware` 0.5.0 (No BC Break)

Conflicts:
	composer.lock
weierophinney added a commit that referenced this pull request Oct 9, 2017
weierophinney added a commit that referenced this pull request Oct 9, 2017
@weierophinney
Copy link
Member

Thanks, @webimpress! I've resolved the merge conflicts before pushing.

@michalbundyra michalbundyra deleted the feature/http-middleware-0.5 branch October 9, 2017 19:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants