Skip to content

Commit 81f2f19

Browse files
committed
Forbid cloning and serialization
1 parent 8fa11fe commit 81f2f19

12 files changed

+60
-0
lines changed

src/DefaultPostgresConnector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Amp\Postgres;
44

55
use Amp\Cancellation;
6+
use Amp\ForbidCloning;
7+
use Amp\ForbidSerialization;
68
use Amp\Sql\SqlConfig;
79
use Amp\Sql\SqlConnector;
810
use Amp\Sql\SqlException;
@@ -12,6 +14,9 @@
1214
*/
1315
final class DefaultPostgresConnector implements SqlConnector
1416
{
17+
use ForbidCloning;
18+
use ForbidSerialization;
19+
1520
/**
1621
* @throws SqlException If connecting fails.
1722
*

src/Internal/AbstractHandle.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Amp\Postgres\Internal;
44

55
use Amp\DeferredFuture;
6+
use Amp\ForbidCloning;
7+
use Amp\ForbidSerialization;
68
use Amp\Pipeline\Queue;
79
use Amp\Postgres\ByteA;
810
use Amp\Postgres\PostgresConfig;
@@ -14,6 +16,9 @@
1416
*/
1517
abstract class AbstractHandle implements PostgresHandle
1618
{
19+
use ForbidCloning;
20+
use ForbidSerialization;
21+
1722
protected ?DeferredFuture $pendingOperation = null;
1823

1924
/** @var array<non-empty-string, Queue> */

src/Internal/ArrayParser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Postgres\ParseException;
68

79
/**
810
* @internal
911
*/
1012
final class ArrayParser
1113
{
14+
use ForbidCloning;
15+
use ForbidSerialization;
16+
1217
/**
1318
* @param string $data String representation of PostgresSQL array.
1419
* @param \Closure(string):mixed $cast Callback to cast parsed values.

src/Internal/PgSqlResultIterator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Postgres\ParseException;
68
use Amp\Postgres\PostgresResult;
79
use Amp\Sql\SqlException;
@@ -12,6 +14,9 @@
1214
*/
1315
final class PgSqlResultIterator
1416
{
17+
use ForbidCloning;
18+
use ForbidSerialization;
19+
1520
/**
1621
* @param array<int, PgSqlType> $types
1722
*

src/Internal/PgSqlResultSet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Future;
68
use Amp\Postgres\PostgresResult;
79

@@ -12,6 +14,9 @@
1214
*/
1315
final class PgSqlResultSet implements PostgresResult, \IteratorAggregate
1416
{
17+
use ForbidCloning;
18+
use ForbidSerialization;
19+
1520
private readonly \Iterator $iterator;
1621

1722
private readonly int $rowCount;

src/Internal/PostgresConnectionListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Postgres\PostgresListener;
68
use Amp\Postgres\PostgresNotification;
79
use function Amp\async;
@@ -12,6 +14,9 @@
1214
*/
1315
final class PostgresConnectionListener implements PostgresListener, \IteratorAggregate
1416
{
17+
use ForbidCloning;
18+
use ForbidSerialization;
19+
1520
/** @var null|\Closure(non-empty-string):void */
1621
private ?\Closure $unlisten;
1722

src/Internal/PostgresConnectionStatement.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
namespace Amp\Postgres\Internal;
44

55
use Amp\DeferredFuture;
6+
use Amp\ForbidCloning;
7+
use Amp\ForbidSerialization;
68
use Amp\Postgres\PostgresStatement;
79
use Amp\Sql\Result;
810
use Amp\Sql\SqlException;
911

1012
/** @internal */
1113
final class PostgresConnectionStatement implements PostgresStatement
1214
{
15+
use ForbidCloning;
16+
use ForbidSerialization;
17+
1318
private int $lastUsedAt;
1419

1520
private readonly DeferredFuture $onClose;

src/Internal/PostgresHandleConnection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Amp\Cancellation;
66
use Amp\DeferredFuture;
7+
use Amp\ForbidCloning;
8+
use Amp\ForbidSerialization;
79
use Amp\Postgres\Internal;
810
use Amp\Postgres\PostgresConfig;
911
use Amp\Postgres\PostgresConnection;
@@ -18,6 +20,9 @@
1820
/** @internal */
1921
abstract class PostgresHandleConnection implements PostgresConnection
2022
{
23+
use ForbidCloning;
24+
use ForbidSerialization;
25+
2126
/** @var DeferredFuture|null Used to only allow one transaction at a time. */
2227
private ?DeferredFuture $busy = null;
2328

src/Internal/PostgresPooledListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Postgres\PostgresListener;
68
use Amp\Postgres\PostgresNotification;
79
use Revolt\EventLoop;
@@ -12,6 +14,9 @@
1214
*/
1315
final class PostgresPooledListener implements PostgresListener, \IteratorAggregate
1416
{
17+
use ForbidCloning;
18+
use ForbidSerialization;
19+
1520
private readonly PostgresListener $listener;
1621

1722
/** @var null|\Closure():void */

src/Internal/PqBufferedResultSet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Future;
68
use Amp\Postgres\PostgresResult;
79
use pq;
@@ -13,6 +15,9 @@
1315
*/
1416
final class PqBufferedResultSet implements PostgresResult, \IteratorAggregate
1517
{
18+
use ForbidCloning;
19+
use ForbidSerialization;
20+
1621
private readonly \Generator $iterator;
1722

1823
private readonly int $rowCount;

src/Internal/PqUnbufferedResultSet.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Future;
68
use Amp\Postgres\PostgresResult;
79
use pq;
@@ -14,6 +16,9 @@
1416
*/
1517
final class PqUnbufferedResultSet implements PostgresResult, \IteratorAggregate
1618
{
19+
use ForbidCloning;
20+
use ForbidSerialization;
21+
1722
private readonly \Generator $generator;
1823

1924
private readonly int $columnCount;

src/Internal/StatementStorage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Amp\Postgres\Internal;
44

5+
use Amp\ForbidCloning;
6+
use Amp\ForbidSerialization;
57
use Amp\Future;
68

79
/**
@@ -11,6 +13,9 @@
1113
*/
1214
final class StatementStorage
1315
{
16+
use ForbidCloning;
17+
use ForbidSerialization;
18+
1419
public int $refCount = 1;
1520

1621
/**

0 commit comments

Comments
 (0)