diff --git a/src/Driver/Driver.php b/src/Driver/Driver.php index 533fb6f7..379041fc 100644 --- a/src/Driver/Driver.php +++ b/src/Driver/Driver.php @@ -16,6 +16,9 @@ use Cycle\Database\Config\PDOConnectionConfig; use Cycle\Database\Config\ProvidesSourceString; use Cycle\Database\Event\QueryExecuted; +use Cycle\Database\Event\TransactionBeginning; +use Cycle\Database\Event\TransactionCommited; +use Cycle\Database\Event\TransactionRolledBack; use Cycle\Database\EventDispatcherAwareInterface; use Cycle\Database\EventDispatcherAwareTrait; use Cycle\Database\Exception\DriverException; @@ -358,6 +361,8 @@ public function beginTransaction(string $isolationLevel = null): bool $this->createSavepoint($this->transactionLevel); + $this->eventDispatcher?->dispatch(new TransactionBeginning($this)); + return true; } @@ -399,6 +404,8 @@ public function commitTransaction(): bool $this->releaseSavepoint($this->transactionLevel + 1); + $this->eventDispatcher?->dispatch(new TransactionCommited($this)); + return true; } @@ -436,6 +443,8 @@ public function rollbackTransaction(): bool $this->rollbackSavepoint($this->transactionLevel + 1); + $this->eventDispatcher?->dispatch(new TransactionRolledBack($this)); + return true; } diff --git a/src/Driver/Postgres/PostgresDriver.php b/src/Driver/Postgres/PostgresDriver.php index be60e157..d823b8da 100644 --- a/src/Driver/Postgres/PostgresDriver.php +++ b/src/Driver/Postgres/PostgresDriver.php @@ -19,6 +19,7 @@ use Cycle\Database\Driver\Postgres\Query\PostgresInsertQuery; use Cycle\Database\Driver\Postgres\Query\PostgresSelectQuery; use Cycle\Database\Driver\Postgres\Query\PostgresUpdateQuery; +use Cycle\Database\Event\TransactionBeginning; use Cycle\Database\Exception\DriverException; use Cycle\Database\Exception\StatementException; use Cycle\Database\Query\QueryBuilder; @@ -180,6 +181,8 @@ public function beginTransaction(string $isolationLevel = null): bool $this->createSavepoint($this->transactionLevel); + $this->eventDispatcher?->dispatch(new TransactionBeginning($this)); + return true; } diff --git a/src/Event/AbstractDriverEvent.php b/src/Event/AbstractDriverEvent.php new file mode 100644 index 00000000..10fc6bd1 --- /dev/null +++ b/src/Event/AbstractDriverEvent.php @@ -0,0 +1,13 @@ +