I would like to know how I can access route parameter in a middleware in Slim 4.
Provided I define a route with placeholder and attached middleware:
<?php
// ...
$app
->get('/{userId}', Controller::class)
->add(Middleware::class);
I would like to access value of {userId}
from middleware before the controller is inovked:
class Middleware
{
function __invoke($request, $handler)
{
// Resolve user ID in this scope?..
return $handler->handle($request);
}
}
I know that in Slim 3 we could do it accessing attributes of request object, however, it does not work in Slim 4. The attributes of route object contain the following entries:
__routingResults__
__route__
__basePath__
Non of these seems to contain parameters.