Merge branch 'develop'

This commit is contained in:
Alejandro Celaya 2016-10-23 10:30:36 +02:00
commit 48acded6ed
2 changed files with 17 additions and 0 deletions

View file

@ -37,6 +37,11 @@ class PathVersionMiddleware implements MiddlewareInterface
$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);

View file

@ -44,4 +44,16 @@ class PathVersionMiddlewareTest extends TestCase
$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);
});
}
}