Skip to content

1.0.0

Choose a tag to compare

@roxblnfk roxblnfk released this 24 Jun 11:22
1.0.0
6f851f3

The first stable release of cycle/transaction — a small transaction abstraction for Cycle ORM that runs raw DBAL operations and a scoped Entity Manager within a single database transaction.

composer require cycle/transaction

Highlights

Transaction::transact()

Execute a callback inside a single database transaction. The callback receives a scoped EntityManagerInterface and the resolved DatabaseInterface; the transaction is committed when the callback returns and rolled back if it throws.

$user = $transaction->transact(function (EntityManagerInterface $em, DatabaseInterface $db): User {
    $user = new User('john@example.com');
    $em->persist($user);

    return $user;
});

Flush modes

The FlushMode enum controls when and how the scoped Entity Manager flushes its pending changes:

Mode Behaviour
OnWrite Flush every persist/persistState/delete immediately.
BeforeCommit Collect all changes and flush once, right before committing. (default)
FailOnPending Throw a TransactionException if any changes are left unflushed.
SkipPending Silently discard any unflushed changes (only DBAL operations are committed).

Transaction modes

The TransactionMode enum controls how the Unit of Work interacts with the open transaction: Current (reuse the open transaction, default), OpenNew (open a dedicated inner transaction per connection) and Ignore (do not manage transactions for the Unit of Work).

Connection scoping

The target database is resolved from the $source argument — either by connection name or by an entity class mapped to it. The scoped Entity Manager rejects entities that belong to a different connection, preventing accidental cross-connection writes.

Requirements

  • PHP 8.2 or higher
  • cycle/orm ^2.18
  • cycle/database ^2.20

Full Changelog: https://github.com/cycle/transaction/commits/1.0.0