With the cake/database module version ^4 I was able to add the PDO connection container definition with the getConnection() method like this:
PDO::class => function (ContainerInterface $container) {
$connection = $container->get(Connection::class);
$connection->getDriver()->connect();
return $connection->getDriver()->getConnection(); // Returned instance of \PDO
},
In Cake 5 database, this function doesn’t exist any more, but there is getPdo() that returns the PDO connection instance. The issue is that it’s protected meaning I can’t access it in my container definition.
Entire function
// Line 239
protected function getPdo(): PDO
{
if ($this->pdo === null) {
$this->connect();
}
assert($this->pdo !== null);
return $this->pdo;
}
How can I access the PDO connection directly? If there is no other way, would it make sense to change the visibility scope from protected to public? I need it for my integration testing environment.