Download the PHP package aegisora/boolean-rule-guardian without Composer
On this page you can find all versions of the php package aegisora/boolean-rule-guardian. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/boolean-rule-guardian
More information about aegisora/boolean-rule-guardian
Files in aegisora/boolean-rule-guardian
Package boolean-rule-guardian
Short Description A simple shortcut for boolean value validation using aegisora/guardian and aegisora/boolean-rule.
License MIT
Homepage https://github.com/Aegisora/boolean-rule-guardian
Informations about the package boolean-rule-guardian
Aegisora Boolean Rule Guardian
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:
โจ Features
- ๐น Simple shortcut API for
BooleanRule - ๐น Validates whether a value is strictly
trueor strictlyfalse - ๐น Uses strict comparison (
===) โ no type juggling - ๐น Uses
aegisora/guardianinternally - ๐น Uses
aegisora/boolean-ruleinternally - ๐น 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
๐ Core Concept
This package wraps the common validation flow:
into a dedicated shortcut class:
Instead of manually creating BooleanRule and passing it to Guardian, you can use BooleanRuleGuardian directly.
๐๏ธ Basic Usage
โ Truthy vs Falsy
The package exposes two methods that differ only in the expected boolean value.
checkTruthy()
Passes when the value is strictly true.
checkFalsy()
Passes when the value is strictly false.
Both methods use strict comparison (===). No type juggling is performed โ only real booleans are accepted as valid input (see Exceptions).
๐งฉ Usage with Custom Exception
You may provide your own exception for validation failure.
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
๐จ 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
Thrown when validation fails and no custom exception is provided.
The rule code for failed boolean validation is boolean_rule.
Custom exception
When a custom exception is passed as the last argument, it is thrown instead of GuardianValidationException on validation failure.
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.
๐งฉ API
BooleanRuleGuardian::checkTruthy()
Validates that $value is strictly true (=== true).
BooleanRuleGuardian::checkFalsy()
Validates that $value is strictly false (=== false).
Parameters (both methods):
$value(mixed) โ value to validate; must be a real boolean$exception(?\Throwable, defaultnull) โ 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:
With custom exception:
๐๏ธ Architecture
This package is a small shortcut layer over the Aegisora validation pipeline.
Flow:
BooleanRuleGuardian::checkTruthy()/checkFalsy()is calledBooleanRule::createTruthy()/BooleanRule::createFalsy()is createdGuardianexecutes the rule- If validation succeeds, execution continues normally
- If validation fails, the custom exception or
GuardianValidationExceptionis thrown - If rule execution fails,
GuardianExecutingRuleExceptionis thrown
Internal flow:
๐ Related Packages
- aegisora/guardian โ validation execution orchestrator
- aegisora/boolean-rule โ rule-based boolean validation
- aegisora/rule-contract โ base rule contract and validation result architecture
โ๏ธ License
This package is open-source and licensed under the MIT License. See the LICENSE for details.
๐ฑ Contributing
Contributions are welcome and greatly appreciated!. See the CONTRIBUTING for details.
๐ Support
If you find this project useful, please consider giving it a star on GitHub!
It helps the project grow and motivates further development.