Download the PHP package aegisora/scalar-equality-rule-guardian without Composer
On this page you can find all versions of the php package aegisora/scalar-equality-rule-guardian. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/scalar-equality-rule-guardian
More information about aegisora/scalar-equality-rule-guardian
Files in aegisora/scalar-equality-rule-guardian
Package scalar-equality-rule-guardian
Short Description Scalar Equality Rule Guardian provides a simple shortcut for scalar equality validation using aegisora/guardian and aegisora/scalar-equality-rule
License MIT
Homepage https://github.com/Aegisora/scalar-equality-rule-guardian
Informations about the package scalar-equality-rule-guardian
Aegisora Scalar Equality Rule Guardian
Scalar Equality Rule Guardian provides a simple shortcut for scalar equality validation using aegisora/guardian and aegisora/scalar-equality-rule.
It is designed for cases where you want to quickly check whether a scalar value is (or is not) strictly equal to an expected scalar value, without manually building a ScalarEqualityRule and a validation pipeline by hand.
This package is built on top of:
โจ Features
- ๐น Simple shortcut API for
ScalarEqualityRule - ๐น Validates strict equality (
===) viacheckEqual() - ๐น Validates strict inequality (
!==) viacheckNotEqual() - ๐น Works with any scalar value (
int,float,string,bool) andnull - ๐น Uses
aegisora/guardianinternally - ๐น Uses
aegisora/scalar-equality-ruleinternally - ๐น Supports a custom validation exception
- ๐น 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 scalar equality validation flow:
into a dedicated shortcut class:
Instead of manually creating a ScalarEqualityRule and passing it to Guardian, you can use ScalarEqualityRuleGuardian directly.
๐๏ธ Basic Usage
checkEqual() passes when $value === $expectedValue, and fails otherwise.
checkNotEqual() is the exact opposite โ it passes when $value !== $expectedValue.
โ How scalar equality works
Comparison is strict (===), so both type and value must match:
And the inverse for checkNotEqual():
Both the value and the expected value must be scalar or null. Passing an array, object, resource or callable cannot be executed as a scalar comparison and throws a rule execution exception.
๐งฉ Usage with Custom Exception
You may provide your own exception for validation failure. It must be the last argument.
If the values are not equal, the provided exception will be thrown instead of GuardianValidationException.
This is useful when validation errors should have domain-specific meaning.
๐งช Example in Application Service
๐จ Exceptions
The package raises two kinds of validation-related exceptions, both delegated to Guardian (the outcome of running the rule):
GuardianValidationException
Thrown when validation fails and no custom exception is provided.
The rule code for a failed scalar equality check is scalar_equality_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 fails to execute (raises a RuleException during validation), as opposed to simply reporting an invalid result.
This happens when the value or the expected value is neither scalar nor null (e.g. an array, object, resource or callable).
๐งฉ API
ScalarEqualityRuleGuardian::checkEqual()
Validates that $value is strictly equal (===) to $expectedValue.
ScalarEqualityRuleGuardian::checkNotEqual()
Validates that $value is strictly not equal (!==) to $expectedValue.
Arguments (both methods):
$valueโ the scalar (ornull) value to validate$expectedValueโ the scalar (ornull) value to compare against$exceptionโ an optional custom\Throwableto be thrown on validation failure
Both methods return void. They communicate results through exceptions only โ they return nothing on success and throw on failure:
GuardianValidationExceptionโ the equality/inequality check failed and no custom exception was provided- the provided custom exception โ the check failed and a custom exception was passed
GuardianExecutingRuleExceptionโ the value or expected value is not scalar (and notnull), so the rule could not be executed
๐๏ธ Architecture
This package is a small shortcut layer over the Aegisora validation pipeline.
Flow:
ScalarEqualityRuleGuardian::checkEqual()/checkNotEqual()is called with a value, an expected value and an optional exception- A
ScalarEqualityRuleis created (createEqual()orcreateNotEqual()) Guardianexecutes the rule against the value- If the check passes, execution continues normally
- If the check fails, the custom exception or
GuardianValidationExceptionis thrown - If the value is not scalar (and not
null),GuardianExecutingRuleExceptionis thrown
Internal flow:
๐ Related Packages
- aegisora/guardian โ validation execution orchestrator
- aegisora/scalar-equality-rule โ scalar equality rule
- 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.
All versions of scalar-equality-rule-guardian with dependencies
aegisora/guardian Version ^1.0
aegisora/scalar-equality-rule Version ^1.0