PHPackages                             aegisora/any-of-rule - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. aegisora/any-of-rule

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

aegisora/any-of-rule
====================

Any Of Rule provides a simple, rule-based logical OR validation implementation for the Aegisora ecosystem.

v1.0.0(today)00MITPHPPHP &gt;=7.4

Since Aug 14Pushed todayCompare

[ Source](https://github.com/Aegisora/any-of-rule)[ Packagist](https://packagist.org/packages/aegisora/any-of-rule)[ Docs](https://github.com/Aegisora/any-of-rule)[ RSS](/packages/aegisora-any-of-rule/feed)WikiDiscussions main Synced today

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

Aegisora Any Of Rule
====================

[](#aegisora-any-of-rule)

[![Latest Version](https://camo.githubusercontent.com/dc667ce262ccf55d0d8279eb3846d0f0c733fbf42b491b6391a45efed7759b98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61656769736f72612f616e792d6f662d72756c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aegisora/any-of-rule)[![Total Downloads](https://camo.githubusercontent.com/e3b66d212f8557d3a93b2b4e43408d98dfe3ca2e924e7f7328f56b05a02d306f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61656769736f72612f616e792d6f662d72756c653f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aegisora/any-of-rule)[![Code Coverage Badge](./badge.svg)](./badge.svg)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHPStan Badge](https://camo.githubusercontent.com/83dd3d35cebed0eab9ee97ff1a5849c1344cda6a8ee9cac2cda20f5aa55b67bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/83dd3d35cebed0eab9ee97ff1a5849c1344cda6a8ee9cac2cda20f5aa55b67bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d627269676874677265656e2e7376673f7374796c653d666c6174)

Any Of Rule provides a simple, rule-based logical **OR** validation implementation for the Aegisora ecosystem.

It is built on top of [`aegisora/rule-contract`](https://github.com/Aegisora/rule-contract) and follows its strict validation architecture, ensuring consistent and predictable behavior across applications.

This rule is useful whenever a value is acceptable if it satisfies **at least one** of several alternative rules — for example, accepting either an email or a phone number, matching one of several allowed formats, or passing any one of a set of business constraints.

---

📑 Table of Contents
-------------------

[](#-table-of-contents)

- [Features](#-features)
- [Installation](#-installation)
- [Core Concept](#-core-concept)
- [Basic Usage](#-basic-usage)
- [Valid vs Invalid](#-valid-vs-invalid)
- [Validation Result](#-validation-result)
- [Guardian Usage](#-guardian-usage)
- [Real-World Examples](#-real-world-examples)
- [Factory Methods](#-factory-methods)
- [Architecture](#-architecture)
- [License](#-license)
- [Contributing](#-contributing)
- [Support](#-support)

---

✨ Features
----------

[](#-features)

- 🔹 Lightweight and dependency-free except `aegisora/rule-contract`
- 🔹 Validates that a value satisfies **at least one** of several rules (logical OR)
- 🔹 Short-circuits on the first rule that passes
- 🔹 Accepts a `RuleContextCollection` of `(rule, context)` pairs
- 🔹 Rejects a non-collection or an empty collection as an invalid context
- 🔹 Fully compatible with Aegisora validation pipeline
- 🔹 Strict `Context` → `Result` validation flow
- 🔹 No raw booleans — only structured results
- 🔹 Safe execution via base `Rule` abstraction
- 🔹 Simple factory API (create)
- 🔹 Ready to use out of the box

---

📦 Installation
--------------

[](#-installation)

```
composer require aegisora/any-of-rule
```

---

🚀 Core Concept
--------------

[](#-core-concept)

This package implements a single validation rule:

- accepts a `RuleContextCollection` via `Context`
- runs each inner rule against its own context
- passes as soon as **any** inner rule reports a valid result
- returns a standardized `Result`

Under the hood it wraps the common boilerplate:

```
foreach ($ruleContextCollection as $ruleContext) {
    if ($ruleContext->getRule()->validate($ruleContext->getContext())->isValid()) {
        // at least one rule passed
    }
}
```

into a reusable rule that reports its outcome through a `Result` object instead of a raw boolean.

---

🏗️ Basic Usage
--------------

[](#️-basic-usage)

```
use Aegisora\RuleContract\Models\Context;
use Aegisora\RuleContract\Models\RuleContext;
use Aegisora\RuleContract\Models\RuleContextCollection;
use Aegisora\Rules\AnyOfRule;

$result = AnyOfRule::create()->validate(
    Context::create(
        RuleContextCollection::create(
            RuleContext::create($emailRule, Context::create($value)),
            RuleContext::create($phoneRule, Context::create($value))
        )
    )
);

if ($result->isValid()) {
    // value satisfied at least one rule
} else {
    // value satisfied none of the rules
}
```

---

✅ Valid vs Invalid
------------------

[](#-valid-vs-invalid)

The rule passes when at least one inner rule is valid and fails only when every inner rule is invalid.

### Valid

[](#valid)

```
$rule = AnyOfRule::create();

// passes — the first rule is valid
$rule->validate(
    Context::create(
        RuleContextCollection::create(
            RuleContext::create($validRule, Context::create($value))
        )
    )
);

// passes — at least one rule in the collection is valid
$rule->validate(
    Context::create(
        RuleContextCollection::create(
            RuleContext::create($invalidRule, Context::create($value)),
            RuleContext::create($validRule, Context::create($value))
        )
    )
);
```

### Invalid

[](#invalid)

```
$rule = AnyOfRule::create();

// fails — every rule in the collection is invalid
$rule->validate(
    Context::create(
        RuleContextCollection::create(
            RuleContext::create($invalidRule, Context::create($value)),
            RuleContext::create($invalidRule, Context::create($value))
        )
    )
);
```

---

🧪 Validation Result
-------------------

[](#-validation-result)

If at least one inner rule is valid, the rule returns a valid result.

`$result->isValid(); // true`

If every inner rule is invalid, the rule returns an invalid result.

```
$result->isValid(); // false
$result->getFailedRuleCode(); // any_of_rule
```

If the context value is not a `RuleContextCollection`, or the collection is empty, the rule throws:

`Aegisora\RuleContract\Exceptions\InvalidRuleContextException`

---

🔗 Guardian Usage
----------------

[](#-guardian-usage)

This rule can be used together with `aegisora/guardian` to build fluent validation pipelines.

```
use Aegisora\Guardian\Guardian;
use Aegisora\RuleContract\Models\Context;
use Aegisora\RuleContract\Models\RuleContext;
use Aegisora\RuleContract\Models\RuleContextCollection;
use Aegisora\Rules\AnyOfRule;
use App\Exceptions\InvalidValueException;

$guardian = new Guardian();

$guardian
    ->that(
        RuleContextCollection::create(
            RuleContext::create($emailRule, Context::create($value)),
            RuleContext::create($phoneRule, Context::create($value))
        )
    )
    ->must(AnyOfRule::create(), new InvalidValueException())
    ->validate();
```

If none of the rules pass, `Guardian` throws the provided domain exception.

---

🧭 Real-World Examples
---------------------

[](#-real-world-examples)

Any Of Rule is useful whenever a value has several acceptable alternatives.

Examples

```
Contact:

accept the value if it is a valid email OR a valid phone number

```

```
Identifiers:

accept either a UUID OR a numeric id

```

```
Formats:

allow a date in one of several supported formats

```

```
Access:

grant access if any one of several permission rules is satisfied

```

---

🧩 Factory Methods
-----------------

[](#-factory-methods)

`AnyOfRule::create();`

- no arguments — creates a new rule instance

`AnyOfRule::create()->validate($context);`

- `$context` — `Context` wrapping the `RuleContextCollection` to validate

---

🏛️ Architecture
---------------

[](#️-architecture)

This package relies on [`aegisora/rule-contract`](https://github.com/Aegisora/rule-contract).

Flow:

1. `validate()` is called
2. `Context` is passed in
3. The `RuleContextCollection` is extracted from context (non-collections and empty collections raise `InvalidRuleContextException`)
4. Each `RuleContext` is validated against its own `Context`
5. The rule passes on the first valid result and fails if none are valid
6. `Result` is returned — valid on success, invalid with the `any_of_rule` code on failure

All logic is safely handled by Rule contract.

---

⚖️ License
----------

[](#️-license)

This package is open-source and licensed under the MIT License. See the [LICENSE](LICENSE) for details.

---

🌱 Contributing
--------------

[](#-contributing)

Contributions are welcome and greatly appreciated! See the [CONTRIBUTING](CONTRIBUTING.md) for details.

---

🌟 Support
---------

[](#-support)

If you find this project useful, please consider giving it a star on GitHub!

It helps the project grow and motivates further development.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 81.3% 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

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/81402dcd0a07ad550b7f80f5871e7c302770b29d4c73a52fc35ba697f702d56e?d=identicon)[arslanim](/maintainers/arslanim)

---

Top Contributors

[![arslanim](https://avatars.githubusercontent.com/u/22678154?v=4)](https://github.com/arslanim "arslanim (13 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")

---

Tags

aegisoraaegisora-ecosystemany-ofany-of-rulelogical-orphprulesvalidationvalidatorphpvalidatorvalidationruleaegisoraaegisora-ecosystemany-ofany-of-rulelogical-or

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aegisora-any-of-rule/health.svg)

```
[![Health](https://phpackages.com/badges/aegisora-any-of-rule/health.svg)](https://phpackages.com/packages/aegisora-any-of-rule)
```

###  Alternatives

[illuminatech/validation-composite

Allows uniting several validation rules into a single one for easy re-usage

180544.2k](/packages/illuminatech-validation-composite)

PHPackages © 2026

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