PHPackages                             antonforwork/rules - 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. antonforwork/rules

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

antonforwork/rules
==================

Business rules

v1.0(4y ago)24PHPPHP &gt;=7.2

Since Aug 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/antonforwork/rules)[ Packagist](https://packagist.org/packages/antonforwork/rules)[ RSS](/packages/antonforwork-rules/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Business rules manager
======================

[](#business-rules-manager)

installation
------------

[](#installation)

`compose require antonforwork/rules`

usage
-----

[](#usage)

#### Create rules with predicates

[](#create-rules-with-predicates)

```
$rule1 = new \Rules\Rule(['id'=>1, 'name'=>'cart discount', '...etc']);
$rule1->withPredicate(new \Rules\Predicates\Primitives\Gte('total_amount', 4500));

$rule2 = new \Rules\Rule(['id'=>2, 'name'=>'country based promo', '...etc']);
$rule2->withPredicate(new \Rules\Predicates\Primitives\Equals('country','US'));

// build context
$context = new \Rules\Contexts\ArrayContext([
    'country'=> 'US',
    'total_amount'=> 3000,
]);

$manager = new \Rules\Manager();
$manager
    ->addRule($rule1)
    ->addRule($rule2)
    // ...
    ;

$matchedRules = $manager->inspect($context); // will return only 1 item. Rule #2, country based promo
```

### Primitive predicates

[](#primitive-predicates)

---

#### Equals

[](#equals)

```
(new \Rules\Predicates\Primitives\Equals('a', 1));
// Context: a=>1 - true, a=>'1' - true, 'a'=>2 - false
```

---

#### EqualsStrict

[](#equalsstrict)

```
(new \Rules\Predicates\Primitives\EqualsStrict('a', 1));
// Context: a=>1 - true, a=>'1' - false, 'a'=>2 - false
```

---

#### Gt

[](#gt)

```
(new \Rules\Predicates\Primitives\Gt('a', 1));
// Context: a=>0 - false, a=>1 - false, a=>2 - true
```

---

#### Gte

[](#gte)

```
(new \Rules\Predicates\Primitives\Gte('a', 1));
// Context: a=>0 - false, a=>1 - true, a=>2 - true
```

---

#### Lt

[](#lt)

```
(new \Rules\Predicates\Primitives\Lt('a', 1));
// Context: a=>0 - true, a=>1 - false, a=>2 - false
```

---

#### Lte

[](#lte)

```
(new \Rules\Predicates\Primitives\Lte('a', 1));
// Context: a=>0 - true, a=>1 - true, a=>2 - false
```

---

#### InRange

[](#inrange)

```
(new \Rules\Predicates\Primitives\InRange('a', 1, 10));
// Context: a=>1 - true, a=>10 - true, a=>20 - false
```

Logical predicates
------------------

[](#logical-predicates)

---

#### LogicalAnd

[](#logicaland)

```
new \Rules\Predicates\Logical\LogicalAnd(
    (new \Rules\Predicates\Primitives\Equals('a', 1))
    (new \Rules\Predicates\Primitives\Equals('b', 2))
    //...
);
// Context:
//  [a=>1, b=>2] - true
//  [a=>1, b=>3] - false
//  [a=>0, b=>2] - false
```

#### LogicalOr

[](#logicalor)

```
new \Rules\Predicates\Logical\LogicalOr(
    (new \Rules\Predicates\Primitives\Equals('a', 1))
    (new \Rules\Predicates\Primitives\Equals('b', 2))
    //...
);
// Context:
//  [a=>1, b=>2] - true
//  [a=>1, b=>3] - true
//  [a=>0, b=>2] - true
//  [a=>0, b=>3] - false
```

#### LogicalNot

[](#logicalnot)

```
new \Rules\Predicates\Logical\LogicalNot(
    new \Rules\Predicates\Logical\LogicalOr(
        (new \Rules\Predicates\Primitives\Equals('a', 1))
        (new \Rules\Predicates\Primitives\Equals('b', 2))
        //...
    )
);
// Context:
//  [a=>1, b=>2] - false
//  [a=>1, b=>3] - false
//  [a=>0, b=>2] - false
//  [a=>0, b=>3] - true
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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

1735d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8843588?v=4)[Anton](/maintainers/antonforwork)[@antonforwork](https://github.com/antonforwork)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/antonforwork-rules/health.svg)

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

###  Alternatives

[jms/cg

Toolset for generating PHP code

15615.8M8](/packages/jms-cg)

PHPackages © 2026

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