Skip to content

Commit

Permalink
Replace parse_url with nyholm/dsn
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Mar 21, 2022
1 parent b7c4120 commit bec231a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
21 changes: 11 additions & 10 deletions app/dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Monolog\Processor\UidProcessor;
use Nyholm\Dsn\DsnParser;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Container\ContainerInterface;
Expand Down Expand Up @@ -58,14 +59,14 @@
];

if ($settings->has('cache.redis')) {
$dsn = parse_url($settings->getString('cache.redis'));
$dsn = DsnParser::parse($settings->getString('cache.redis'));

$drivers[] = new Redis(
[
'servers' => [
[
'server' => $dsn['host'] ?? 'localhost',
'port' => $dsn['port'] ?? 6379
'server' => $dsn->getHost() ?? 'localhost',
'port' => $dsn->getPort() ?? 6379
]
]
]
Expand Down Expand Up @@ -121,17 +122,17 @@
},
PDO::class => function (ContainerInterface $container): PDO {
$settings = $container->get(SettingsInterface::class);
$dsn = parse_url($settings->getString('db.dsn'));
$dsn = DsnParser::parse($settings->getString('db.dsn'));

return new PDO(
sprintf(
'%s:host=%s;port=%d;dbname=%s;user=%s;password=%s',
$dsn['scheme'] ?? 'pgsql',
$dsn['host'] ?? 'localhost',
$dsn['port'] ?? 5432,
ltrim($dsn['path'] ?? 'postgres', '/'),
$dsn['user'] ?? 'postgres',
$dsn['pass'] ?? '',
$dsn->getScheme() ?? 'pgsql',
$dsn->getHost() ?? 'localhost',
$dsn->getPort() ?? 5432,
ltrim($dsn->getPath() ?? 'postgres', '/'),
$dsn->getUser() ?? 'postgres',
$dsn->getPassword() ?? '',
),
options: [
PDO::ATTR_EMULATE_PREPARES => false,
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"courier/transport-amqp": "dev-main",
"kriswallsmith/buzz": "^1.2",
"monolog/monolog": "^2.3",
"nyholm/dsn": "^2.0",
"nyholm/psr7": "^1.5",
"nyholm/psr7-server": "^1.0",
"php-di/php-di": "^6.3",
Expand Down
40 changes: 20 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bec231a

Please sign in to comment.