PHPackages                             stwarog/uow-fuel - 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. stwarog/uow-fuel

ActiveLibrary

stwarog/uow-fuel
================

Unit of Work feature for Fuel's PHP ORM.

2.0.0(4y ago)31.2k1MITPHPPHP &gt;=8.0.0

Since Dec 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/stwarog/uow-fuel)[ Packagist](https://packagist.org/packages/stwarog/uow-fuel)[ RSS](/packages/stwarog-uow-fuel/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (14)Used By (1)

Fuel PHP ORM's Unit of Work Layer
=================================

[](#fuel-php-orms-unit-of-work-layer)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/aa5364eca26d6639c368915232d28d8b486309882f6fea937dc08651ca98ea9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73747761726f672f756f772d6675656c3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/aa5364eca26d6639c368915232d28d8b486309882f6fea937dc08651ca98ea9c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73747761726f672f756f772d6675656c3f7374796c653d666f722d7468652d6261646765)[![GitHub tag (latest by date)](https://camo.githubusercontent.com/bf30c2abb49135af8ecaf8e27f66b22748a0721a11fa093edb2f3d7305c96414/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f73747761726f672f756f772d6675656c3f636f6c6f723d253233376266633033267374796c653d666f722d7468652d6261646765266c6162656c3d76657273696f6e)](https://camo.githubusercontent.com/bf30c2abb49135af8ecaf8e27f66b22748a0721a11fa093edb2f3d7305c96414/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f73747761726f672f756f772d6675656c3f636f6c6f723d253233376266633033267374796c653d666f722d7468652d6261646765266c6162656c3d76657273696f6e)

### Foreword

[](#foreword)

This package is an extension for [UOW Core](https://github.com/stwarog/uow) for Fuel PHP Framework. At this moment it supports ORM models (with relations).

#### Zero configuration installation

[](#zero-configuration-installation)

```
composer require stwarog/uow-fuel
```

Just find some place to initialize this package (wrap it to the singleton or use dependency injection container), then call:

```
FuelEntityManager::forge($db, $config = []);
```

DB must be a reference to your instance of this class (it is globally available in Fuel). [UOW Core](https://github.com/stwarog/uow) will use existing (and configured) object to build queries based on resolved criteria.

Take a look at [configuration guide](https://github.com/stwarog/uow#config) to change default behaviour of package.

### The problem &amp; Goal

[](#the-problem--goal)

Fuel's ORM is convenient in use. We can use OOP syntax to handle relations, batch update etc. Assuming we have `Todo` model with many `Lines`, let's compare result of test below:

##### Fuel's way

[](#fuels-way)

```
DB::start_transation();
try {
    $todo = Model_Todo::query()->related('lines')->where('id', 1)->get_one();
    $todo->status = 2;

    foreach ($todo->lines as $line) {
        $rand = rand(0, 5);
        $line->content = 'changed' . $rand;
    }

    $todo->save();
} catch (Exception $e) {
    DB::rollback_transation();
    throw $e;
}
DB::commit_transation();
```

but the *problem* is that the Fuel will produce for example (writing part):

```
# transaction start

UPDATE `todo_table` SET `status` = 2 WHERE `id` = 1;
UPDATE `lines_table` SET `content` = changed1 WHERE `id` = 1;
UPDATE `lines_table` SET `content` = changed2 WHERE `id` = 2;
UPDATE `lines_table` SET `content` = changed1 WHERE `id` = 3;
UPDATE `lines_table` SET `content` = changed4 WHERE `id` = 4;
...
UPDATE `lines_table` SET `content` = changed1 WHERE `id` = 150;

# transaction commit
```

In case we have much more related lines it might be a huge performance hit.

##### "Unit of Work" approach

[](#unit-of-work-approach)

Let's refactor code above to this plugin syntax:

```
$entityManager = FuelEntityManager::forge($db, $config = []);

$todo = Model_Todo::query()->related('lines')->where('id', 1)->get_one();
$todo->status = 2;

foreach ($todo->lines as $line) {
    $rand = rand(0, 5);
    $line->content = 'changed' . $rand;
}

$entityManager->save($todo);
$entityManager->flush();

# or inline $entityManager->save($todo, $flush = true)
```

Script will group changed table columns &amp; fields and built query in more elegant way! All will be wrapped in transaction out of the box.

```
# transaction start

UPDATE `todo_table` SET `status` = 2 WHERE `id` IN (1);
UPDATE `lines_table` SET `content` = changed1 WHERE `id` IN (1,2,3,4,5,6,7,8,9...10);
UPDATE `lines_table` SET `content` = changed2 WHERE `id` IN (11,12,13,14,15,16,17,18,19...100);

# transaction commit
```

Of course these examples are trivial. In real life each model may have a lots of nested relations. Entity Manager will take care how final query should looks like.

#### Contribution

[](#contribution)

Please take a look at core [contribution guide](https://github.com/stwarog/uow#contribution).

#### License

[](#license)

MIT

### Change Log

[](#change-log)

##### 1.4.0 (2021-07-21)

[](#140-2021-07-21)

- Upgraded core package to 1.4.0
- Implemented no longer new in FuelModelAdapter.php
- Unit tests configuration + pseudo Mock of Fuel`s ORM

##### 1.3.1 (2021-07-10)

[](#131-2021-07-10)

- Upgraded core package to 1.3.1

##### 1.3.0 (2021-06-23)

[](#130-2021-06-23)

- Upgraded core package to 1.3.0
- Reduced phpstan errors to 2

##### 1.2.0 (2021-06-21)

[](#120-2021-06-21)

- upgraded core package to 1.2.0
- added ./tests to .gitignore
- installed &amp; configured PHPCS, PHPSTAN

##### 1.1.3 (2021-01-04)

[](#113-2021-01-04)

- *398d1247* used the most recent version of uow core

##### 1.1.2 (2021-01-03)

[](#112-2021-01-03)

- *a0bf93b7* used array\_diff\_assoc instead of array\_diff due no columns were checked

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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

Every ~35 days

Recently: every ~55 days

Total

13

Last Release

1563d ago

Major Versions

1.4.0 → 2.0.02022-01-27

PHP version history (2 changes)1.0.0-alphaPHP &gt;=7.1

2.0.0PHP &gt;=8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5630a890882d4aa41d529e372c96340d27466720d7afb78c8a2f5945987a82f9?d=identicon)[seigba](/maintainers/seigba)

---

Top Contributors

[![serek-dev](https://avatars.githubusercontent.com/u/6751932?v=4)](https://github.com/serek-dev "serek-dev (11 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stwarog-uow-fuel/health.svg)

```
[![Health](https://phpackages.com/badges/stwarog-uow-fuel/health.svg)](https://phpackages.com/packages/stwarog-uow-fuel)
```

###  Alternatives

[fuel/fuel

FuelPHP is a simple, flexible, community driven PHP 5.4+ framework, based on the best ideas of other frameworks, with a fresh start!

1.5k42.3k](/packages/fuel-fuel)

PHPackages © 2026

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