Skip to content

v1.2.0

Choose a tag to compare

@SoloPHP SoloPHP released this 30 Oct 19:17
· 3 commits to main since this release

Solo Repository 1.2 adds TransactionManager, which gives services transaction boundaries over the application's DBAL connection without handing them SQL access.

Features

  • TransactionManager::run() runs a callback in Connection::transactional() on the connection the repositories already use, and returns its result:

    use Solo\Repository\TransactionManager;
    
    $transactions = new TransactionManager($db); // $products also uses $db
    $transactions->run(static function () use ($products, $id): void {
        $products->update($id, ['sku' => 'TABLE-02']);
        $products->translations()->save($id, 'uk', ['name' => 'Стіл']);
        $products->links('tags')->sync($id, [2, 5]);
    });

    Construction opens no connection, and the manager never closes the application connection. DBAL keeps commit, rollback and nested savepoints: a successful nested run does not commit the outer transaction, and a caught inner failure rolls back to its savepoint. Callback results keep their type through PHPDoc generics. There are no retries, after-commit callbacks or distributed transactions, and repositories on another connection do not participate.

Upgrade

composer update solophp/repository

See Transactions and the DBAL escape hatch, the changelog and the full diff since 1.1.0.