PHPackages                             aegisora/boolean-rule-guardian - 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/boolean-rule-guardian

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

aegisora/boolean-rule-guardian
==============================

A simple shortcut for boolean value validation using aegisora/guardian and aegisora/boolean-rule.

v1.0.0(today)01↑2900%MITPHPPHP &gt;=7.4

Since Jul 31Pushed todayCompare

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

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

Aegisora Boolean Rule Guardian
==============================

[](#aegisora-boolean-rule-guardian)

[![Latest Version](https://camo.githubusercontent.com/50e68a6b1a89520ed4f5df01f78f1a0e383373aeeb8fbbd6bf2a5d83fa32f0a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61656769736f72612f626f6f6c65616e2d72756c652d677561726469616e3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aegisora/boolean-rule-guardian)[![Total Downloads](https://camo.githubusercontent.com/bc832803fe3dea15b8a5b052dbf2fe15e15c1cea9b994e968b0cb5d7cea33f06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61656769736f72612f626f6f6c65616e2d72756c652d677561726469616e3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aegisora/boolean-rule-guardian)[![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)

Boolean Rule Guardian provides a simple shortcut for boolean value validation using `aegisora/guardian` and `aegisora/boolean-rule`.

It is designed for cases where you want to quickly check whether a value is strictly `true` or strictly `false` without manually creating validation pipelines.

This package is built on top of:

- [aegisora/guardian](https://github.com/Aegisora/guardian)
- [aegisora/boolean-rule](https://github.com/Aegisora/boolean-rule)

---

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

[](#-features)

- 🔹 Simple shortcut API for `BooleanRule`
- 🔹 Validates whether a value is strictly `true` or strictly `false`
- 🔹 Uses strict comparison (`===`) — no type juggling
- 🔹 Uses `aegisora/guardian` internally
- 🔹 Uses `aegisora/boolean-rule` internally
- 🔹 Supports custom validation exceptions
- 🔹 Keeps rule execution errors separated from validation errors
- 🔹 Fully compatible with the Aegisora ecosystem
- 🔹 Ready to use out of the box

---

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

[](#-installation)

```
composer require aegisora/boolean-rule-guardian
```

---

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

[](#-core-concept)

This package wraps the common validation flow:

```
$guardian->check($value, BooleanRule::createTruthy(), new NotTruthyException());
```

into a dedicated shortcut class:

```
$booleanRuleGuardian->checkTruthy($value, new NotTruthyException());
```

Instead of manually creating `BooleanRule` and passing it to `Guardian`, you can use `BooleanRuleGuardian` directly.

---

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

[](#️-basic-usage)

```
use Aegisora\Guardian\Guardian;
use Aegisora\Guardian\Exceptions\GuardianValidationException;
use Aegisora\RuleGuardians\BooleanRule\BooleanRuleGuardian;

$guardian = new Guardian();

$booleanRuleGuardian = new BooleanRuleGuardian($guardian);

try {
    $booleanRuleGuardian->checkTruthy(true);
    // value is strictly true
} catch (GuardianValidationException $exception) {
    // value is not true
}
```

---

✅ Truthy vs Falsy
-----------------

[](#-truthy-vs-falsy)

The package exposes two methods that differ only in the expected boolean value.

### `checkTruthy()`

[](#checktruthy)

Passes when the value is strictly `true`.

```
$booleanRuleGuardian->checkTruthy(true);  // passes
$booleanRuleGuardian->checkTruthy(false); // fails
```

### `checkFalsy()`

[](#checkfalsy)

Passes when the value is strictly `false`.

```
$booleanRuleGuardian->checkFalsy(false); // passes
$booleanRuleGuardian->checkFalsy(true);  // fails
```

Both methods use strict comparison (`===`). No type juggling is performed — only real booleans are accepted as valid input (see [Exceptions](#-exceptions)).

---

🧩 Usage with Custom Exception
-----------------------------

[](#-usage-with-custom-exception)

You may provide your own exception for validation failure.

```
use Aegisora\Guardian\Guardian;
use Aegisora\RuleGuardians\BooleanRule\BooleanRuleGuardian;
use App\Exceptions\NotTruthyException;

$guardian = new Guardian();

$booleanRuleGuardian = new BooleanRuleGuardian($guardian);

$booleanRuleGuardian->checkTruthy(false, new NotTruthyException());
```

If the value is not `true`, the provided exception will be thrown.

This is useful when validation errors should have domain-specific meaning.

---

🧪 Example in Application Service
--------------------------------

[](#-example-in-application-service)

```
use Aegisora\RuleGuardians\BooleanRule\BooleanRuleGuardian;
use App\Exceptions\ConsentRequiredException;

final class RegistrationService
{
    private BooleanRuleGuardian $booleanRuleGuardian;

    public function __construct(
        BooleanRuleGuardian $booleanRuleGuardian
    ) {
        $this->booleanRuleGuardian = $booleanRuleGuardian;
    }

    public function register(bool $termsAccepted): void
    {
        $this->booleanRuleGuardian->checkTruthy($termsAccepted, new ConsentRequiredException());

        // business logic for an accepted agreement
    }
}
```

---

🚨 Exceptions
------------

[](#-exceptions)

This package does not define its own exception types. It delegates execution to `Guardian` and re-throws the exceptions raised by the underlying pipeline.

### `GuardianValidationException`

[](#guardianvalidationexception)

Thrown when validation fails and no custom exception is provided.

The rule code for failed boolean validation is `boolean_rule`.

```
use Aegisora\Guardian\Exceptions\GuardianValidationException;

try {
    $booleanRuleGuardian->checkTruthy(false);
} catch (GuardianValidationException $exception) {
    echo $exception->getRuleCode(); // "boolean_rule"
}
```

### Custom exception

[](#custom-exception)

When a custom exception is passed as the last argument, it is thrown instead of `GuardianValidationException` on validation failure.

```
use App\Exceptions\NotTruthyException;

try {
    $booleanRuleGuardian->checkTruthy(false, new NotTruthyException());
} catch (NotTruthyException $exception) {
    // domain-specific handling
}
```

### `GuardianExecutingRuleException`

[](#guardianexecutingruleexception)

Thrown when the underlying rule execution fails.

This happens, for example, when the value is not a real boolean (e.g. `1`, `'true'`, `''`, `[]`, `null`). The rule only accepts `true` or `false`; any other type is treated as an execution error, not a validation failure.

```
use Aegisora\Guardian\Exceptions\GuardianExecutingRuleException;

try {
    $booleanRuleGuardian->checkTruthy(1); // not a real boolean
} catch (GuardianExecutingRuleException $exception) {
    // the rule could not be executed
}
```

---

🧩 API
-----

[](#-api)

### `BooleanRuleGuardian::checkTruthy()`

[](#booleanruleguardianchecktruthy)

```
/**
 * @param mixed $value
 * @throws GuardianExecutingRuleException
 * @throws GuardianValidationException
 * @throws \Throwable
 */
public function checkTruthy(
    $value,
    ?\Throwable $exception = null
): void
```

Validates that `$value` is strictly `true` (`=== true`).

### `BooleanRuleGuardian::checkFalsy()`

[](#booleanruleguardiancheckfalsy)

```
/**
 * @param mixed $value
 * @throws GuardianExecutingRuleException
 * @throws GuardianValidationException
 * @throws \Throwable
 */
public function checkFalsy(
    $value,
    ?\Throwable $exception = null
): void
```

Validates that `$value` is strictly `false` (`=== false`).

Parameters (both methods):

- `$value` *(mixed)* — value to validate; must be a real boolean
- `$exception` *(?\\Throwable, default `null`)* — optional custom exception thrown on validation failure

Both methods return `void`. They communicate results through exceptions only — they return nothing on success and throw on failure:

- `GuardianValidationException` — validation failed and no custom exception was provided
- the provided custom exception — validation failed and a custom exception was passed
- `GuardianExecutingRuleException` — the underlying rule failed to execute (e.g. the value is not a real boolean)

Example:

```
$booleanRuleGuardian->checkTruthy(true);
```

With custom exception:

```
$booleanRuleGuardian->checkFalsy(true, new NotFalsyException());
```

---

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

[](#️-architecture)

This package is a small shortcut layer over the Aegisora validation pipeline.

Flow:

1. `BooleanRuleGuardian::checkTruthy()` / `checkFalsy()` is called
2. `BooleanRule::createTruthy()` / `BooleanRule::createFalsy()` is created
3. `Guardian` executes the rule
4. If validation succeeds, execution continues normally
5. If validation fails, the custom exception or `GuardianValidationException` is thrown
6. If rule execution fails, `GuardianExecutingRuleException` is thrown

Internal flow:

```
Value → BooleanRuleGuardian → Guardian → BooleanRule → Result → Exception

```

---

🔗 Related Packages
------------------

[](#-related-packages)

- [aegisora/guardian](https://github.com/Aegisora/guardian) — validation execution orchestrator
- [aegisora/boolean-rule](https://github.com/Aegisora/boolean-rule) — rule-based boolean validation
- [aegisora/rule-contract](https://github.com/Aegisora/rule-contract) — base rule contract and validation result architecture

---

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

[](#️-license)

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

---

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

[](#-contributing)

Contributions are welcome and greatly appreciated!. See the CONTRIBUTING 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

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76% 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 (19 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (6 commits)")

---

Tags

aegisoraaegisora-ecosystembooleanboolean-checkboolean-ruleguardianphprule-guardianrulesvalidationphpvalidationrulebooleanguardianaegisoraaegisora-ecosystemrule-guardianboolean-checkboolean-rule

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/aegisora-boolean-rule-guardian/health.svg)

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

PHPackages © 2026

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