Closed sridesmet closed 5 years ago
Both the route arguments and request attributes are supposed to be usable as controller parameters (see https://github.com/PHP-DI/Slim-Bridge/blob/master/src/ControllerInvoker.php#L44-L48), so that should work.
Could you check that that the parameters do exist in the request attirbutes?
This works:
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
print($request->getAttribute('myArgument'));
}
But when passed to the__invoke
function, it does not:
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next, $myArgument)
{
print($myArgument);
}
Edit: When I edit the ControllerInvoker to print out the attribute in the $parameters array, it exists.
I see the group middleware is called first, then the route middleware, then the actual Handler. But the Controllerinvoker is only called on the Handler, not on the middleware.
Ah OK sorry, indeed that works with controllers, not middlewares right now.
Oh, I see. I will use $request->getAttribute()
in middlewares then :)
👍
When I have an invokable class Middleware, the attributes of the previous middleware are not getting injected in the __invoke($request, $response, $next, $sampleAttribute) function. It results in:
Is this by design or not supported?