dbalConnection)) { $this->dbalConnection = $this->createDbalConnection(); } return $this->dbalConnection; } public function getPDO(): PDO { if (!isset($this->pdo)) { $this->pdo = $this->createPDO(); } return $this->pdo; } /** * Clone with another PDO connection. */ public function withPDO(PDO $pdo): self { $obj = clone $this; $obj->pdo = $pdo; $obj->dbalConnection = null; return $obj; } /** * Create a PDO connection. */ public function createPDO(?DatabaseParams $params = null): PDO { $params = $params ?? $this->databaseParamsFactory->create(); return $this->pdoFactoryFactory ->create($params->getPlatform() ?? '') ->create($params); } private function createDbalConnection(): DbalConnection { $params = $this->databaseParamsFactory->create(); $platform = $params->getPlatform(); if (!$platform) { throw new RuntimeException("No database platform."); } return $this->dbalConnectionFactoryFactory ->create($platform, $this->getPDO()) ->create($params); } /** * Get a database type (MySQL, MariaDB, PostgreSQL). */ public function getType(): string { return $this->createDetailsProvider()->getType(); } /** * Get a database version. */ public function getVersion(): string { return $this->createDetailsProvider()->getVersion(); } /** * Get a database parameter. */ public function getParam(string $name): ?string { return $this->createDetailsProvider()->getParam($name); } /** * Get a database server version string. */ public function getServerVersion(): string { return $this->createDetailsProvider()->getServerVersion(); } private function createDetailsProvider(): DetailsProvider { $platform = $this->configDataProvider->getPlatform(); return $this->detailsProviderFactory->create($platform, $this->getPDO()); } }