aegisora / scalar-equality-rule
Rule-based scalar equality validation in Aegisora ecosystem
Requires
- php: >=7.4
- aegisora/rule-contract: ^1.0
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6
- squizlabs/php_codesniffer: ^4.0
README
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.
✨ Features
- 🔹 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
📦 Installation
composer require aegisora/scalar-equality-rule
🚀 Core Concept
This 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.
🏗️ Basic Usage
✅ Equality check
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 }
❌ Inequality check
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) }
🧩 Factory Methods
ScalarEqualityRule::createEqual($expectedValue); ScalarEqualityRule::createNotEqual($expectedValue);
$expectedValue— scalar value ornull
⚠️ Validation Rules
Both expected value and input value must be:
- scalar (
int,float,string,bool) - or
null
Otherwise, an exception will be thrown:
Aegisora\RuleContract\Exceptions\InvalidRuleContextException
🏛️ Architecture
This 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.
⚖️ 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.