zendframework / zend-stratigility

Middleware for PHP built on top of PSR-7 and PSR-15
BSD 3-Clause "New" or "Revised" License
235 stars 57 forks source link

Backport #165 to v2.2 release #167

Closed weierophinney closed 6 years ago

weierophinney commented 6 years ago

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.