Scalar Equality Rule provides a simple, rule-based scalar value comparison 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.
- 🔹 Lightweight and dependency-free (except rule contract)
- 🔹 Strict scalar comparison using
=== - 🔹 Supports both equality and inequality checks
- 🔹 Fully compatible with Aegisora validation pipeline
- 🔹 Strict
Context → Resultvalidation flow - 🔹 No raw booleans — only structured results
- 🔹 Safe execution via base
Ruleabstraction - 🔹 Convenient factory methods (
createEqual,createNotEqual) - 🔹 Built-in validation of input values
composer require aegisora/scalar-equality-ruleThis package implements scalar comparison validation:
- accepts a value via
Context - compares it to an expected scalar value
- uses strict comparison (
===) - returns a standardized
Result
Supported values:
- scalar types (
int,float,string,bool) null
Any non-scalar value will result in an exception.
use Aegisora\Rules\ScalarEqualityRule;
use Aegisora\RuleContract\Models\Context;
$result = ScalarEqualityRule::createEqual(42)->validate(Context::create(42));
if ($result->isValid()) {
// values are equal
} else {
// values are NOT equal
}use Aegisora\Rules\ScalarEqualityRule;
use Aegisora\RuleContract\Models\Context;
$result = ScalarEqualityRule::createNotEqual(42)->validate(Context::create(100));
if ($result->isValid()) {
// values are NOT equal (as expected)
} else {
// values are equal (unexpected)
}ScalarEqualityRule::createEqual($expectedValue);
ScalarEqualityRule::createNotEqual($expectedValue);$expectedValue— scalar value ornull
Both expected value and input value must be:
- scalar (
int,float,string,bool) - or
null
Otherwise, an exception will be thrown:
Aegisora\RuleContract\Exceptions\InvalidRuleContextExceptionThis package relies on aegisora/rule-contract (https://github.com/Aegisora/rule-contract).
Validation flow:
validate()is calledContextis passed inexecuteValidate()runs- Values are validated as scalar or null
- Strict comparison (
===) is performed Resultis returned
All logic is safely encapsulated within the base Rule abstraction.
This package is open-source and licensed under the MIT License. See the LICENSE for details.
Contributions are welcome and greatly appreciated!. See the CONTRIBUTING for details.
If you find this project useful, please consider giving it a star on GitHub!
It helps the project grow and motivates further development.