. */ declare(strict_types=1); namespace App\Doctrine\Middleware; use Composer\CaBundle\CaBundle; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; /** * This middleware sets SSL options for MySQL connections */ class MySQLSSLConnectionMiddlewareDriver extends AbstractDriverMiddleware { public function __construct(Driver $wrappedDriver, private readonly bool $enabled, private readonly bool $verify = true) { parent::__construct($wrappedDriver); } public function connect(array $params): Connection { //Only set this on MySQL connections, as other databases don't support this parameter if($this->enabled && $this->getDatabasePlatform() instanceof AbstractMySQLPlatform) { $params['driverOptions'][\PDO::MYSQL_ATTR_SSL_CA] = CaBundle::getSystemCaRootBundlePath(); $params['driverOptions'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = $this->verify; } return parent::connect($params); } }