I learn zend expressive and I have some questions about factories.
So, I can get a session in middleware:
...
/** @var Zend\Expressive\Session\LazySession $session */
$session = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE);
...
However, if I want to create a custom service with session dependency I need to get session instance into factory.
class AuthServiceFactory
{
public function __invoke(ContainerInterface $container): HttpAuthService
{
// get instance $userRepository
// get instance $session
return new HttpAuthService(
$userRepository,
$session
);
}
}
When I try to get request instance from container:
public function __invoke(ContainerInterface $container): HttpAuthService
{
dd($container->get(\Psr\Http\Message\ServerRequestInterface::class));
}
it returns Closure.
I think request is not initialized at this step.
My task is to make a service for authorization, which should save authenticated user to the session.
Tell me, please, how can I get the request and session instances correctly?
Maybe, Do I not understand how zend expressive works?