Description
The PDO
class connects to the DB server during its instantiation, making it a heavy constructor that is not desirable when using DI.
Symfony components generally either use the doctrine/dbal API (which connects lazily) or support passing a PDO DSN to connect lazily internally.
Btw, another drawback of the current approach is that it won't play well with long-running processes (while using AI in a messenger consumer can definitely be a legitimate case) as the connection can be closed or can timeout. In particular, the fromDbal
static constructor extracting the native connection from a DBAL connection won't play well with cases where the DBAL connection gets closed and connects again later (common in messenger consumers) as that would create a new native connection.