. */ namespace SP\Infrastructure\Database; use Exception; use PDO; use function SP\__u; /** * Class PDOWrapper */ class PDOWrapper { /** * Build a PDO object with the given connection data and options * * @throws DatabaseException */ public function build(string $connectionUri, DatabaseConnectionData $connectionData, array $opts): PDO { try { return new PDO( $connectionUri, $connectionData->getDbUser(), $connectionData->getDbPass(), $opts ); } catch (Exception $e) { throw DatabaseException::critical( __u('Unable to connect to DB'), sprintf('Error %s: %s', $e->getCode(), $e->getMessage()), $e->getCode(), $e ); } } }