+
+ /**
+ * Takes an array of settings and return the DNS string. Key names can be
+ * 'database', 'hostspec', 'port', 'username', 'password' but aliases
+ * 'dbname', 'host' and 'user' are also supported.
+ *
+ * @return string
+ *
+ */
+ public static function generateDSN($aInfo)
+ {
+ $sDSN = sprintf(
+ 'pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s;',
+ $aInfo['host'] ?? $aInfo['hostspec'] ?? '',
+ $aInfo['port'] ?? '',
+ $aInfo['dbname'] ?? $aInfo['database'] ?? '',
+ $aInfo['user'] ?? '',
+ $aInfo['password'] ?? ''
+ );
+ $sDSN = preg_replace('/\b\w+=;/', '', $sDSN);
+ $sDSN = preg_replace('/;\Z/', '', $sDSN);
+
+ return $sDSN;
+ }