diff --git a/src/Internal/PostgresHandleConnection.php b/src/Internal/PostgresHandleConnection.php index 137846e..b6b1252 100644 --- a/src/Internal/PostgresHandleConnection.php +++ b/src/Internal/PostgresHandleConnection.php @@ -31,7 +31,7 @@ abstract public static function connect( ?Cancellation $cancellation = null, ): self; - protected function __construct(private readonly PostgresHandle $handle) + protected function __construct(protected readonly PostgresHandle $handle) { } diff --git a/src/PgSqlConnection.php b/src/PgSqlConnection.php index c15023b..0a4652a 100644 --- a/src/PgSqlConnection.php +++ b/src/PgSqlConnection.php @@ -20,7 +20,10 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati throw new \Error('ext-pgsql is not compatible with pecl-ev; use pecl-pq or a different loop extension'); } // @codeCoverageIgnoreEnd - if (!$connection = \pg_connect($config->getConnectionString(), \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW)) { + if (!$connection = \pg_connect( + $config->getConnectionString(), + \PGSQL_CONNECT_ASYNC | \PGSQL_CONNECT_FORCE_NEW, + )) { throw new ConnectionException("Failed to create connection resource"); } @@ -36,7 +39,14 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati $deferred = new DeferredFuture(); /** @psalm-suppress MissingClosureParamType $resource is a resource and cannot be inferred in this context */ - $callback = static function (string $callbackId, $resource) use (&$poll, &$await, $connection, $config, $deferred, $hash): void { + $callback = static function (string $callbackId, $resource) use ( + &$poll, + &$await, + $connection, + $config, + $deferred, + $hash, + ): void { switch ($result = \pg_connect_poll($connection)) { case \PGSQL_POLLING_READING: case \PGSQL_POLLING_WRITING: @@ -47,7 +57,7 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati break; case \PGSQL_POLLING_OK: - $deferred->complete(new self($connection, $resource, $hash, $config)); + $deferred->complete(new self(new Internal\PgSqlHandle($connection, $resource, $hash, $config))); break; default: @@ -69,14 +79,4 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati EventLoop::cancel($await); } } - - /** - * @param \PgSql\Connection $handle PostgreSQL connection handle. - * @param resource $socket PostgreSQL connection stream socket. - * @param string $id Connection identifier for determining which cached type table to use. - */ - protected function __construct(\PgSql\Connection $handle, $socket, string $id, PostgresConfig $config) - { - parent::__construct(new Internal\PgSqlHandle($handle, $socket, $id, $config)); - } } diff --git a/src/PqConnection.php b/src/PqConnection.php index 23a94c2..9deb2f1 100644 --- a/src/PqConnection.php +++ b/src/PqConnection.php @@ -10,8 +10,6 @@ final class PqConnection extends Internal\PostgresHandleConnection implements PostgresConnection { - private readonly Internal\PqHandle $handle; - public static function connect(PostgresConfig $config, ?Cancellation $cancellation = null): self { try { @@ -35,7 +33,7 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati break; case pq\Connection::POLLING_OK: - $deferred->complete(new self($connection, $config)); + $deferred->complete(new self(new Internal\PqHandle($connection, $config))); break; default: @@ -58,12 +56,6 @@ public static function connect(PostgresConfig $config, ?Cancellation $cancellati } } - protected function __construct(pq\Connection $handle, PostgresConfig $config) - { - $this->handle = new Internal\PqHandle($handle, $config); - parent::__construct($this->handle); - } - /** * @return bool True if result sets are buffered in memory, false if unbuffered. */