Hi,
is it possible to extend the container inside a middleware?
I want to get an route parameter (exmp. id) inside a middleware.
The problem is, that I cant acces the Requests Route object inside my Container creation.
Inside a middleware I can access ist but cant extend the container.
Snipper for Container
//... getContainer and other deps.
$container["id"] = function($container){
//Cant acces route params inside here
$data = $container["idManager"]->getSessionData();
if( !empty($data["id"]) ){
return (int) $data["id"];
}
return null;
};
Middleware
public function __invoke(Request $request, Response $response, $next)
$id= $request->getAttribute("route")->getArgument("id");
if( !$this->_container["id"] ){
//This doesnt works.
$this->_container->extend("id", function($container) use($id){
return $id;
});
}
}
So does anyone knows a solution.
I need the id before the route callback is dispatched.