In my container my DB connection definition is as follows:
Connection::class => function (ContainerInterface $container) {
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = $container->get('settings')['db'];
$cnx = DriverManager::getConnection($connectionParams,$config);
return $cnx;
}
This works just fine. I am about to implement DB audit tables and I would to set a DB environment variable each time a connection is injected into any repository. I can do this by setting a variable so my container would look like:
Connection::class => function (ContainerInterface $container) {
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = $container->get('settings')['db'];
$cnx = DriverManager::getConnection($connectionParams,$config);
**$cnx->executeQuery('set @auditUserId=##');**
return $cnx;
}
Where ## is the UID claim from the JWT. However, in Slim4 the request, and thus the JWT, isn’t available in the container definition. What’s the best way to accomplish this?