From 81f2f192f8627794dc13a65d478f8ec517114d16 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sun, 17 Dec 2023 10:39:43 -0600 Subject: [PATCH] Forbid cloning and serialization --- src/DefaultPostgresConnector.php | 5 +++++ src/Internal/AbstractHandle.php | 5 +++++ src/Internal/ArrayParser.php | 5 +++++ src/Internal/PgSqlResultIterator.php | 5 +++++ src/Internal/PgSqlResultSet.php | 5 +++++ src/Internal/PostgresConnectionListener.php | 5 +++++ src/Internal/PostgresConnectionStatement.php | 5 +++++ src/Internal/PostgresHandleConnection.php | 5 +++++ src/Internal/PostgresPooledListener.php | 5 +++++ src/Internal/PqBufferedResultSet.php | 5 +++++ src/Internal/PqUnbufferedResultSet.php | 5 +++++ src/Internal/StatementStorage.php | 5 +++++ 12 files changed, 60 insertions(+) diff --git a/src/DefaultPostgresConnector.php b/src/DefaultPostgresConnector.php index adc2e40..c249c9f 100644 --- a/src/DefaultPostgresConnector.php +++ b/src/DefaultPostgresConnector.php @@ -3,6 +3,8 @@ namespace Amp\Postgres; use Amp\Cancellation; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Sql\SqlConfig; use Amp\Sql\SqlConnector; use Amp\Sql\SqlException; @@ -12,6 +14,9 @@ */ final class DefaultPostgresConnector implements SqlConnector { + use ForbidCloning; + use ForbidSerialization; + /** * @throws SqlException If connecting fails. * diff --git a/src/Internal/AbstractHandle.php b/src/Internal/AbstractHandle.php index 9576261..277777c 100644 --- a/src/Internal/AbstractHandle.php +++ b/src/Internal/AbstractHandle.php @@ -3,6 +3,8 @@ namespace Amp\Postgres\Internal; use Amp\DeferredFuture; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Pipeline\Queue; use Amp\Postgres\ByteA; use Amp\Postgres\PostgresConfig; @@ -14,6 +16,9 @@ */ abstract class AbstractHandle implements PostgresHandle { + use ForbidCloning; + use ForbidSerialization; + protected ?DeferredFuture $pendingOperation = null; /** @var array */ diff --git a/src/Internal/ArrayParser.php b/src/Internal/ArrayParser.php index 78ff5c6..9e81a1e 100644 --- a/src/Internal/ArrayParser.php +++ b/src/Internal/ArrayParser.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Postgres\ParseException; /** @@ -9,6 +11,9 @@ */ final class ArrayParser { + use ForbidCloning; + use ForbidSerialization; + /** * @param string $data String representation of PostgresSQL array. * @param \Closure(string):mixed $cast Callback to cast parsed values. diff --git a/src/Internal/PgSqlResultIterator.php b/src/Internal/PgSqlResultIterator.php index b845027..d3e414f 100644 --- a/src/Internal/PgSqlResultIterator.php +++ b/src/Internal/PgSqlResultIterator.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Postgres\ParseException; use Amp\Postgres\PostgresResult; use Amp\Sql\SqlException; @@ -12,6 +14,9 @@ */ final class PgSqlResultIterator { + use ForbidCloning; + use ForbidSerialization; + /** * @param array $types * diff --git a/src/Internal/PgSqlResultSet.php b/src/Internal/PgSqlResultSet.php index ad638d6..59da60d 100644 --- a/src/Internal/PgSqlResultSet.php +++ b/src/Internal/PgSqlResultSet.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Future; use Amp\Postgres\PostgresResult; @@ -12,6 +14,9 @@ */ final class PgSqlResultSet implements PostgresResult, \IteratorAggregate { + use ForbidCloning; + use ForbidSerialization; + private readonly \Iterator $iterator; private readonly int $rowCount; diff --git a/src/Internal/PostgresConnectionListener.php b/src/Internal/PostgresConnectionListener.php index f82285e..3b29f1c 100644 --- a/src/Internal/PostgresConnectionListener.php +++ b/src/Internal/PostgresConnectionListener.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Postgres\PostgresListener; use Amp\Postgres\PostgresNotification; use function Amp\async; @@ -12,6 +14,9 @@ */ final class PostgresConnectionListener implements PostgresListener, \IteratorAggregate { + use ForbidCloning; + use ForbidSerialization; + /** @var null|\Closure(non-empty-string):void */ private ?\Closure $unlisten; diff --git a/src/Internal/PostgresConnectionStatement.php b/src/Internal/PostgresConnectionStatement.php index aa0e470..6ee32ef 100644 --- a/src/Internal/PostgresConnectionStatement.php +++ b/src/Internal/PostgresConnectionStatement.php @@ -3,6 +3,8 @@ namespace Amp\Postgres\Internal; use Amp\DeferredFuture; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Postgres\PostgresStatement; use Amp\Sql\Result; use Amp\Sql\SqlException; @@ -10,6 +12,9 @@ /** @internal */ final class PostgresConnectionStatement implements PostgresStatement { + use ForbidCloning; + use ForbidSerialization; + private int $lastUsedAt; private readonly DeferredFuture $onClose; diff --git a/src/Internal/PostgresHandleConnection.php b/src/Internal/PostgresHandleConnection.php index 2653aa3..e46d03d 100644 --- a/src/Internal/PostgresHandleConnection.php +++ b/src/Internal/PostgresHandleConnection.php @@ -4,6 +4,8 @@ use Amp\Cancellation; use Amp\DeferredFuture; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Postgres\Internal; use Amp\Postgres\PostgresConfig; use Amp\Postgres\PostgresConnection; @@ -18,6 +20,9 @@ /** @internal */ abstract class PostgresHandleConnection implements PostgresConnection { + use ForbidCloning; + use ForbidSerialization; + /** @var DeferredFuture|null Used to only allow one transaction at a time. */ private ?DeferredFuture $busy = null; diff --git a/src/Internal/PostgresPooledListener.php b/src/Internal/PostgresPooledListener.php index 8368389..d965e74 100644 --- a/src/Internal/PostgresPooledListener.php +++ b/src/Internal/PostgresPooledListener.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Postgres\PostgresListener; use Amp\Postgres\PostgresNotification; use Revolt\EventLoop; @@ -12,6 +14,9 @@ */ final class PostgresPooledListener implements PostgresListener, \IteratorAggregate { + use ForbidCloning; + use ForbidSerialization; + private readonly PostgresListener $listener; /** @var null|\Closure():void */ diff --git a/src/Internal/PqBufferedResultSet.php b/src/Internal/PqBufferedResultSet.php index 890398d..9660768 100644 --- a/src/Internal/PqBufferedResultSet.php +++ b/src/Internal/PqBufferedResultSet.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Future; use Amp\Postgres\PostgresResult; use pq; @@ -13,6 +15,9 @@ */ final class PqBufferedResultSet implements PostgresResult, \IteratorAggregate { + use ForbidCloning; + use ForbidSerialization; + private readonly \Generator $iterator; private readonly int $rowCount; diff --git a/src/Internal/PqUnbufferedResultSet.php b/src/Internal/PqUnbufferedResultSet.php index 0417d0c..e23baf6 100644 --- a/src/Internal/PqUnbufferedResultSet.php +++ b/src/Internal/PqUnbufferedResultSet.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Future; use Amp\Postgres\PostgresResult; use pq; @@ -14,6 +16,9 @@ */ final class PqUnbufferedResultSet implements PostgresResult, \IteratorAggregate { + use ForbidCloning; + use ForbidSerialization; + private readonly \Generator $generator; private readonly int $columnCount; diff --git a/src/Internal/StatementStorage.php b/src/Internal/StatementStorage.php index a0c012a..48b8477 100644 --- a/src/Internal/StatementStorage.php +++ b/src/Internal/StatementStorage.php @@ -2,6 +2,8 @@ namespace Amp\Postgres\Internal; +use Amp\ForbidCloning; +use Amp\ForbidSerialization; use Amp\Future; /** @@ -11,6 +13,9 @@ */ final class StatementStorage { + use ForbidCloning; + use ForbidSerialization; + public int $refCount = 1; /**