Skip to content

Commit

Permalink
Add support for missing Postgres connection options (#54101)
Browse files Browse the repository at this point in the history
* Add support for missing Postgres connection options

* Update PostgresConnector.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
Maniload and taylorotwell authored Jan 8, 2025
1 parent 5459817 commit 36a4a53
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions src/Illuminate/Database/Connectors/PostgresConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ protected function getDsn(array $config)
$dsn .= ";application_name='".str_replace("'", "\'", $application_name)."'";
}

return $this->addSslOptions($dsn, $config);
$dsn = $this->addSslOptions($dsn, $config);

return $this->addPostgresOptions($dsn, $config);
}

/**
Expand All @@ -162,7 +164,62 @@ protected function getDsn(array $config)
*/
protected function addSslOptions($dsn, array $config)
{
foreach (['sslmode', 'sslcert', 'sslkey', 'sslrootcert'] as $option) {
foreach ([
'sslmode',
'sslcert',
'sslkey',
'sslrootcert',
'requiressl',
'sslnegotiation',
'sslcompression',
'sslpassword',
'sslcertmode',
'sslcrl',
'sslcrldir',
'sslsni',
] as $option) {
if (isset($config[$option])) {
$dsn .= ";{$option}={$config[$option]}";
}
}

return $dsn;
}

/**
* Add Postgres specific options to the DSN.
*
* @param string $dsn
* @param array $config
* @return string
*/
protected function addPostgresOptions($dsn, array $config)
{
foreach ([
'channel_binding',
'connect_timeout',
'fallback_application_name',
'gssdelegation',
'gssencmode',
'gsslib',
'hostaddr',
'keepalives',
'keepalives_count',
'keepalives_idle',
'keepalives_interval',
'krbsrvname',
'load_balance_hosts',
'options',
'passfile',
'replication',
'require_auth',
'requirepeer',
'service',
'ssl_max_protocol_version',
'ssl_min_protocol_version',
'target_session_attrs',
'tcp_user_timeout',
] as $option) {
if (isset($config[$option])) {
$dsn .= ";{$option}={$config[$option]}";
}
Expand Down

0 comments on commit 36a4a53

Please sign in to comment.