I'm trying to accomplish API versioning of the APIs I've written using Slim framework.
All my versioned APIs look like this:
$app->get('/:version/book/search', function() {...});
I'm trying to create an application wide Route Condition for this version as follows:
\Slim\Route::setDefaultConditions(array(
'version' => 'v[3-6]'
));
So only the APIs with version number v3,v4,v5 and v6 should be allowed to get it.
My requirement is to store the exact version of the API call made in $app->version, and then do version specific code changes if needed for that. I have created a middleware which I added to the $app itself, so it gets executed for each API calls:
$app->add(new \GetVerMiddleware());
class GetVerMiddleware extends \Slim\Middleware
{
public function call()
{
// HOW TO GET THE version route parameter??
// ????
$app->version = $version;
$this->next->call();
}
}
So I want to know how to get the route parameter version inside the GetVerMiddleware. Is it even possible to get that? I know how to get the entire route printed (link), but I'm interested only in the version parameter.