PHPackages                             asimlqt/transact - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. asimlqt/transact

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

asimlqt/transact
================

A transaction library for PHP

1.0.0(8y ago)2112Apache-2.0PHPPHP &gt;=5.6.0

Since Jan 22Pushed 8y ago2 watchersCompare

[ Source](https://github.com/asimlqt/transact)[ Packagist](https://packagist.org/packages/asimlqt/transact)[ Docs](https://github.com/asimlqt/transact)[ RSS](/packages/asimlqt-transact/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Transact
========

[](#transact)

Transact is a transaction library for PHP similar to the way database transactions work but for PHP code.

The purpose is to be able to execute multiple actions which might depend on the previous action completing successfully before eexecuting the next one and in case of failure you want to revert back to the original state.

Installation
------------

[](#installation)

Use the following composer command to install

```
composer require asimlqt/transact

```

Example
-------

[](#example)

The following example creates 3 simple actions that echo some text during the `execute` and `revert` methods. This example will be referenced throughout the rest of the README and only changes will be listed.

```
use Asimlqt\Transact\TransactionManager;
use Asimlqt\Transact\Action;
use Asimlqt\Transact\TransactionFailedException;

$transactionManager = new TransactionManager();

class Action1 extends Action {
    public function execute() {
        echo "Action1 execute\n";
    }
    public function revert() {
        echo "Action1 revert\n";
    }
}

class Action2 extends Action {
    public function execute() {
        echo "Action2 execute\n";
    }
    public function revert() {
        echo "Action2 revert\n";
    }
}

class Action3 extends Action {
    public function execute() {
        echo "Action3 execute\n";
    }
    public function revert() {
        echo "Action3 revert\n";
    }
}

$transactionManager
    ->addAction(new Action1())
    ->addAction(new Action2())
    ->addAction(new Action3());

try {
    $transactionManager->execute();
    echo "Transaction completed successfully\n";
} catch (TransactionFailedException $e) {
    echo $e->getMessage() . "\n";
}
```

The output of the program is

```
Action1 execute
Action2 execute
Action3 execute
Transaction completed successfully

```

Order of execution
------------------

[](#order-of-execution)

The actions are executed in the order they are added. When there is an error i.e. when an exception is thrown the `revert` methods will be called in reverse order. The `revert` method of the last successful action will be called first then the one before that etc. all the way to the first action.

For example if the third action threw an exception then the `revert` method of `Action2` will be called then the `revert` method of `Action1`:

```
class Action3 extends Action {
    public function execute() {
        echo "Action3 execute\n";
        throw new Exception();
    }
    public function revert() {
        echo "Action3 revert\n";
    }
}
```

The output of will be:

```
Action1 execute
Action2 execute
Action3 execute
Action2 revert
Action1 revert
Transaction failed

```

You've probably noticed that the `Action3` execute method through an exception so why wasn't the revert method of `Action3` called? That's becasue each action should perform only one task, so if an action threw an exception becasue it couldn't complete the task then there is nothing to revert!

Passing data to actions
-----------------------

[](#passing-data-to-actions)

Usually the actions will need some data to perform their tasks so to do this use the `Intent` object which is a simple wrapper around an array. It only has 2 methods `get` and `set`. This will automatically be injected into the actions before the execute method is called.

```
$intent = new Asimlqt\Transact\Intent();
$intent->set("user", $user);
$transactionManager->setIntent($intent);
```

Then in the Action you can retrieve the user using:

```
    public function execute() {
        $user = $this->getIntent()->get("user");
        ...
    }
```

> Note that the same intent object will be forwarded to all actions so it is possible to overwrite data. It can also be useful if you need to pass data from one action to another.

Retry Policies
--------------

[](#retry-policies)

If an action fails to complete it's task due to some external factor you might want to try the action again e.g. making an API request. Retry policies can be specified for both, `execute` and `revert`. They are action specific so you can only specify a retry policy for only one action or different policies for different actions. The following policies are currently available:

### RetryNone

[](#retrynone)

This is the default policy if you don't explicitly specify one. this does not perform any retries.

### RetryOnce

[](#retryonce)

This will immediately try the action again before marking it as failed.

### RetryNumTimes

[](#retrynumtimes)

This will try the action repeatedly for the specified number of times.

### RetryAfter

[](#retryafter)

This will retry the request once more after a delay of specified microseconds.

You will need to set these on the Action objects before adding them to the transaction manager:

```
$action1 = new Action1();
$action1->setExecuteRetryPolicy(new Asimlqt\Transact\Retry\RetryOnce());
$transactionManager->addAction($action1);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3034d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d1ba605a0d5efec9649a10ac22f37d0c140e8ee928daac34686e987719bee17?d=identicon)[Asim](/maintainers/Asim)

---

Top Contributors

[![asimlqt](https://avatars.githubusercontent.com/u/1963846?v=4)](https://github.com/asimlqt "asimlqt (2 commits)")

---

Tags

phptransaction

### Embed Badge

![Health badge](/badges/asimlqt-transact/health.svg)

```
[![Health](https://phpackages.com/badges/asimlqt-transact/health.svg)](https://phpackages.com/packages/asimlqt-transact)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
