1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-30 04:29:12 +01:00

Remove unneeded str_replace()

ConnectionConfig object made this unnecessary.
This commit is contained in:
Aaron Piotrowski 2020-02-13 17:13:28 -06:00
parent 3a651d66d8
commit 54186c9d26
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
2 changed files with 12 additions and 20 deletions

View File

@ -27,9 +27,7 @@ final class PgSqlConnection extends Connection implements Link
throw new \Error('ext-pgsql is not compatible with pecl-ev; use pecl-pq or a different loop extension');
} // @codeCoverageIgnoreEnd
$connectionString = \str_replace(";", " ", $connectionConfig->getConnectionString());
if (!$connection = @\pg_connect($connectionString, \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) {
if (!$connection = @\pg_connect($connectionConfig->getConnectionString(), \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) {
return new Failure(new ConnectionException("Failed to create connection resource"));
}
@ -43,13 +41,11 @@ final class PgSqlConnection extends Connection implements Link
$deferred = new Deferred;
$callback = function ($watcher, $resource) use ($connection, $deferred) {
$callback = function ($watcher, $resource) use ($connection, $deferred): void {
switch (\pg_connect_poll($connection)) {
case \PGSQL_POLLING_READING:
return; // Connection not ready, poll again.
case \PGSQL_POLLING_WRITING:
return; // Still writing...
case \PGSQL_POLLING_READING: // Connection not ready, poll again.
case \PGSQL_POLLING_WRITING: // Still writing...
return;
case \PGSQL_POLLING_FAILED:
$deferred->fail(new ConnectionException(\pg_last_error($connection)));
@ -66,7 +62,7 @@ final class PgSqlConnection extends Connection implements Link
$promise = $deferred->promise();
$token = $token ?? new NullCancellationToken();
$token = $token ?? new NullCancellationToken;
$id = $token->subscribe([$deferred, "fail"]);
$promise->onResolve(function ($exception) use ($connection, $poll, $await, $id, $token): void {

View File

@ -24,10 +24,8 @@ final class PqConnection extends Connection implements Link
*/
public static function connect(ConnectionConfig $connectionConfig, ?CancellationToken $token = null): Promise
{
$connectionString = \str_replace(";", " ", $connectionConfig->getConnectionString());
try {
$connection = new pq\Connection($connectionString, pq\Connection::ASYNC);
$connection = new pq\Connection($connectionConfig->getConnectionString(), pq\Connection::ASYNC);
} catch (pq\Exception $exception) {
return new Failure(new ConnectionException("Could not connect to PostgreSQL server", 0, $exception));
}
@ -37,13 +35,11 @@ final class PqConnection extends Connection implements Link
$deferred = new Deferred;
$callback = function () use ($connection, $deferred) {
$callback = function () use ($connection, $deferred): void {
switch ($connection->poll()) {
case pq\Connection::POLLING_READING:
return; // Connection not ready, poll again.
case pq\Connection::POLLING_WRITING:
return; // Still writing...
case pq\Connection::POLLING_READING: // Connection not ready, poll again.
case pq\Connection::POLLING_WRITING: // Still writing...
return;
case pq\Connection::POLLING_FAILED:
$deferred->fail(new ConnectionException($connection->errorMessage));
@ -60,7 +56,7 @@ final class PqConnection extends Connection implements Link
$promise = $deferred->promise();
$token = $token ?? new NullCancellationToken();
$token = $token ?? new NullCancellationToken;
$id = $token->subscribe([$deferred, "fail"]);
$promise->onResolve(function () use ($poll, $await, $id, $token): void {