Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Oct 23, 2016
2 parents 27b08ff + 6821f5c commit 48acded
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions module/Rest/src/Middleware/PathVersionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function __invoke(Request $request, Response $response, callable $out = n
$uri = $request->getUri();
$path = $uri->getPath();

// Exclude non-rest route
if (strpos($path, '/rest') !== 0) {
return $out($request, $response);
}

// If the path does not begin with the version number, prepend v1 by default for retrocompatibility purposes
if (strpos($path, '/rest/v') !== 0) {
$parts = explode('/', $path);
Expand Down
12 changes: 12 additions & 0 deletions module/Rest/test/Middleware/PathVersionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ public function versionOneIsPrependedWhenNoVersionIsDefined()
$this->assertEquals('/rest/v1/bar/baz', $req->getUri()->getPath());
});
}

/**
* @test
*/
public function nonRestPathsAreNotProcessed()
{
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/non-rest'));
$test = $this;
$this->middleware->__invoke($request, new Response(), function ($req) use ($request, $test) {
$test->assertSame($request, $req);
});
}
}

0 comments on commit 48acded

Please sign in to comment.