Download the PHP package aegisora/numeric-range-rule-guardian without Composer
On this page you can find all versions of the php package aegisora/numeric-range-rule-guardian. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/numeric-range-rule-guardian
More information about aegisora/numeric-range-rule-guardian
Files in aegisora/numeric-range-rule-guardian
Package numeric-range-rule-guardian
Short Description Numeric Range Rule Guardian provides simple shortcuts for ensuring a numeric value falls within an expected range
License MIT
Homepage https://github.com/Aegisora/numeric-range-rule-guardian
Informations about the package numeric-range-rule-guardian
Aegisora Numeric Range Rule Guardian
Numeric Range Rule Guardian provides simple shortcuts for ensuring a numeric value falls within an expected range using aegisora/guardian and aegisora/numeric-range-rule.
It is designed for cases where you want to quickly check whether a value is greater than, less than, or between given bounds without manually creating validation pipelines.
This package is built on top of:
โจ Features
- ๐น Simple shortcut API for
NumericRangeRule - ๐น Validates lower bounds (
checkGreaterThan,checkGreaterThanOrEqualTo) - ๐น Validates upper bounds (
checkLessThan,checkLessThanOrEqualTo) - ๐น Validates ranges with inclusive/exclusive bounds (
checkBetween,checkBetweenExclusive,checkBetweenMinExclusive,checkBetweenMaxExclusive) - ๐น Works with integers, floats and numeric strings
- ๐น Uses
aegisora/guardianinternally - ๐น Uses
aegisora/numeric-range-ruleinternally - ๐น Supports custom validation exceptions
- ๐น 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 NumericRangeRule and passing it to Guardian, you can use NumericRangeRuleGuardian directly.
๐๏ธ Basic Usage
๐งฉ Usage with Custom Exception
You may provide your own exception for validation failure.
If the value is out of the range, 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. All errors are raised by the underlying aegisora/guardian package.
Both exceptions extend the abstract base class
Aegisora\Guardian\Exceptions\GuardianException,
so you can catch every validation error with a single catch:
GuardianValidationException
Thrown when validation fails and no custom exception is provided.
GuardianExecutingRuleException
Thrown when the underlying rule execution fails, for example when the checked value is not numeric.
Aegisora\Guardian\Exceptions\GuardianExecutingRuleException
๐งฉ API
All methods share the same contract: they return void and communicate results through exceptions only โ nothing is returned on success and an exception is thrown on failure:
GuardianValidationExceptionโ validation failed and no custom exception was providedGuardianExecutingRuleExceptionโ the underlying rule failed to execute (e.g. the value is not numeric)- the provided custom exception โ validation failed and a custom exception was passed
Each method also throws Aegisora\RuleContract\Exceptions\InvalidRuleContextException when the range is configured with invalid bounds (a non-numeric bound, $min greater than $max, or equal bounds where at least one side is exclusive).
NumericRangeRuleGuardian::checkGreaterThan()
Valid when $value > $min.
NumericRangeRuleGuardian::checkGreaterThanOrEqualTo()
Valid when $value >= $min.
NumericRangeRuleGuardian::checkLessThan()
Valid when $value < $max.
NumericRangeRuleGuardian::checkLessThanOrEqualTo()
Valid when $value <= $max.
NumericRangeRuleGuardian::checkBetween()
Valid when $min <= $value <= $max (both bounds inclusive).
NumericRangeRuleGuardian::checkBetweenExclusive()
Valid when $min < $value < $max (both bounds exclusive).
NumericRangeRuleGuardian::checkBetweenMinExclusive()
Valid when $min < $value <= $max (lower bound exclusive, upper bound inclusive).
NumericRangeRuleGuardian::checkBetweenMaxExclusive()
Valid when $min <= $value < $max (lower bound inclusive, upper bound exclusive).
Common parameters:
$value(mixed) โ value to validate; considered valid when it is numeric and satisfies the configured range$min/$max(numeric) โ range bounds$exception(?\Throwable, defaultnull) โ optional custom exception thrown on validation failure
Example:
With custom exception:
๐๏ธ Architecture
This package is a small shortcut layer over the Aegisora validation pipeline.
Flow:
- A
NumericRangeRuleGuardian::check*()method is called - The matching
NumericRangeRule::create*()rule is created Guardianexecutes the rule- If validation succeeds, execution continues normally
- If validation fails, custom exception or
GuardianValidationExceptionis thrown - If rule execution fails,
GuardianExecutingRuleExceptionis thrown
Internal flow:
๐ Related Packages
- aegisora/guardian โ validation execution orchestrator
- aegisora/numeric-range-rule โ rule-based numeric range 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.