Skip to content

Commit

Permalink
Forbid cloning and serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 17, 2023
1 parent 8fa11fe commit 81f2f19
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/DefaultPostgresConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +14,9 @@
*/
final class DefaultPostgresConnector implements SqlConnector
{
use ForbidCloning;
use ForbidSerialization;

/**
* @throws SqlException If connecting fails.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/AbstractHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +16,9 @@
*/
abstract class AbstractHandle implements PostgresHandle
{
use ForbidCloning;
use ForbidSerialization;

protected ?DeferredFuture $pendingOperation = null;

/** @var array<non-empty-string, Queue> */
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/ArrayParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

namespace Amp\Postgres\Internal;

use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Postgres\ParseException;

/**
* @internal
*/
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.
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PgSqlResultIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +14,9 @@
*/
final class PgSqlResultIterator
{
use ForbidCloning;
use ForbidSerialization;

/**
* @param array<int, PgSqlType> $types
*
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PgSqlResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Amp\Postgres\Internal;

use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Future;
use Amp\Postgres\PostgresResult;

Expand All @@ -12,6 +14,9 @@
*/
final class PgSqlResultSet implements PostgresResult, \IteratorAggregate
{
use ForbidCloning;
use ForbidSerialization;

private readonly \Iterator $iterator;

private readonly int $rowCount;
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PostgresConnectionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +14,9 @@
*/
final class PostgresConnectionListener implements PostgresListener, \IteratorAggregate
{
use ForbidCloning;
use ForbidSerialization;

/** @var null|\Closure(non-empty-string):void */
private ?\Closure $unlisten;

Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PostgresConnectionStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
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;

/** @internal */
final class PostgresConnectionStatement implements PostgresStatement
{
use ForbidCloning;
use ForbidSerialization;

private int $lastUsedAt;

private readonly DeferredFuture $onClose;
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PostgresHandleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PostgresPooledListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +14,9 @@
*/
final class PostgresPooledListener implements PostgresListener, \IteratorAggregate
{
use ForbidCloning;
use ForbidSerialization;

private readonly PostgresListener $listener;

/** @var null|\Closure():void */
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PqBufferedResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Amp\Postgres\Internal;

use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Future;
use Amp\Postgres\PostgresResult;
use pq;
Expand All @@ -13,6 +15,9 @@
*/
final class PqBufferedResultSet implements PostgresResult, \IteratorAggregate
{
use ForbidCloning;
use ForbidSerialization;

private readonly \Generator $iterator;

private readonly int $rowCount;
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/PqUnbufferedResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Amp\Postgres\Internal;

use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Future;
use Amp\Postgres\PostgresResult;
use pq;
Expand All @@ -14,6 +16,9 @@
*/
final class PqUnbufferedResultSet implements PostgresResult, \IteratorAggregate
{
use ForbidCloning;
use ForbidSerialization;

private readonly \Generator $generator;

private readonly int $columnCount;
Expand Down
5 changes: 5 additions & 0 deletions src/Internal/StatementStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Amp\Postgres\Internal;

use Amp\ForbidCloning;
use Amp\ForbidSerialization;
use Amp\Future;

/**
Expand All @@ -11,6 +13,9 @@
*/
final class StatementStorage
{
use ForbidCloning;
use ForbidSerialization;

public int $refCount = 1;

/**
Expand Down

0 comments on commit 81f2f19

Please sign in to comment.