Hi. I have API & web routes:
$app->post('/api/action1', Action1::class);
$app->group('/admin', function(RouteCollectorProxy $group) {
$group->get('/page1', Page1::class);
})
->add('csrf')
->add(TwigMiddleware::createFromContainer($app, Twig::class));
In dependencies Twig::class
create CsrfExtension
witch create Guard
object. The last must use session storage to store csrf tokens. So, at finish I got cookie while request to api routes. In any case, it is wrong to create twig object on every api request…
So I need to some “lazy” init TwigMiddleware::createFromContainer($app, Twig::class)
, but have no idea how. I can’t use anonymous function because of
Return value of class@anonymous::handle() must be an instance of Psr\Http\Message\ResponseInterface, instance of Slim\Views\TwigMiddleware returned
error. How can I do this in right way?