Skip to content

Commit 5daf480

Browse files
committed
Use utopia DSN
1 parent 77a8cd4 commit 5daf480

3 files changed

Lines changed: 57 additions & 28 deletions

File tree

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"pcov/clobber": "2.*",
4747
"swoole/ide-helper": "5.1.3",
4848
"utopia-php/cli": "0.14.*",
49+
"utopia-php/dsn": "0.2.*",
4950
"laravel/pint": "1.*",
5051
"phpstan/phpstan": "1.*",
5152
"rregeer/phpunit-coverage-check": "0.3.*"

composer.lock

Lines changed: 50 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Database/PDO.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Utopia\Database;
44

5+
use Utopia\DSN\DSN;
6+
57
/**
68
* A PDO wrapper that forwards method calls to the internal PDO instance.
79
*
@@ -59,36 +61,15 @@ public function reconnect(): void
5961

6062
public function getScheme(): string
6163
{
62-
$parts = $this->parseDsn($this->dsn);
64+
$dsn = new DSN($this->dsn);
6365

64-
return $parts['scheme'] ?? throw new \Exception('No scheme found in DSN');
66+
return $dsn->getScheme();
6567
}
6668

6769
public function getHostname(): string
6870
{
69-
$parts = $this->parseDsn($this->dsn);
70-
71-
return $parts['host'] ?? throw new \Exception('No host found in DSN');
72-
}
73-
74-
/**
75-
* @param string $dsn
76-
* @return array<mixed>
77-
*/
78-
public function parseDsn(string $dsn): array
79-
{
80-
$result = [];
81-
82-
[$driver, $params] = explode(':', $dsn, 2);
83-
$result['driver'] = $driver;
84-
85-
foreach (explode(';', $params) as $pair) {
86-
if (str_contains($pair, '=')) {
87-
[$key, $value] = explode('=', $pair, 2);
88-
$result[$key] = $value;
89-
}
90-
}
71+
$dsn = new DSN($this->dsn);
9172

92-
return $result;
73+
return $dsn->getHost();
9374
}
9475
}

0 commit comments

Comments
 (0)