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

Conversation

weierophinney
Copy link
Member

This patch backports the fix from #165 to the 2.2 series, as the but exists in that version as well.

Essentially, previous versions allowed something like the following:

new PathMiddlewareDecorator('/api', middleware(function ($request, $handler) {
    $uri = $request->getUri();
     if (! preg_match('#^/v\d+/#', $uri->getPath())) {
         $request = $request->withUri($uri->withPath('/v1' . $uri->getPath()));
     }
     return $handler->handle($request);
}));

In the above example, the path /api/books would result in a lower layer receiving /api/v1/books. This worked on versions prior to 2.1, but not in 2.2 or 3.0.

The patch provided here is a backport of the one in #165, and re-worked to work with PHP 5.6 and 7.0.

Backports the test case from zendframework#165, and makes minor changes so it will
execute correctly under the v2.2 series. Test fails as expected.
Updates the `PathRequestHandlerDecorator` to accept a string prefix
instead of a `ServerRequestInterface` to its constructor, and then to
use that to build the request path to pass to the handler. The
`PathMiddlewareDecorator` now passes the prefix instead of the original
request to the `PathRequestHandlerDecorator` constructor.

New test passes, but one existing test fails at this point.
The test testMiddlewareCallingNextWithRequestPassesRequestToNextMiddleware
was using path segregated routes, but they were not pertinent to the
behavior being tested, and, in fact, broke once we fixed the behavior
reported in zendframework#165. The equivalent version 3 tests do not use path
segregated routes, so the path segregation was removed in order to
test the expected behavior correctly.
As we may be targeting an older version of the spec.
@weierophinney weierophinney merged commit 844847f into zendframework:release-2.2 Apr 4, 2018
weierophinney added a commit that referenced this pull request Apr 4, 2018
@weierophinney weierophinney deleted the hotfix/165-path-segregation-and-route-concatenation branch April 4, 2018 17:46
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.

1 participant