aegisora / emptiness-rule
Rule-based emptiness 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
Emptiness Rule provides a simple, rule-based emptiness validation 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 minimal dependencies
- 🔹 Validation for empty and non-empty values
- 🔹 Supports multiple data types (string, array, object, etc.)
- 🔹 Fully compatible with Aegisora validation pipeline
- 🔹 Strict
Context → Resultvalidation flow - 🔹 No raw booleans — only structured results
- 🔹 Safe execution via base
Ruleabstraction - 🔹 Convenient factory methods (
create()) - 🔹 Built-in validation of input values
📦 Installation
composer require aegisora/emptiness-rule
🚀 Core Concept
This package provides validation rules to check whether a value is:
- empty (
EmptyRule) - not empty (
NotEmptyRule)
Validation is performed by:
- receiving a value via
Context - checking it against emptiness criteria
- returning a standardized
Result
📐 What is "empty"?
The following values are considered empty:
null- empty string (
'') - empty array (
[]) - objects implementing
Countablewithcount() === 0
The following are NOT empty:
- non-empty strings
- non-empty arrays
- numbers (
int,float) - booleans
- objects (unless
Countableand empty)
🏗️ Basic Usage
✅ Check if value is NOT empty
use Aegisora\Rules\Emptiness\NotEmptyRule; use Aegisora\RuleContract\Models\Context; $result = NotEmptyRule::create()->validate(Context::create('hello')); if ($result->isValid()) { // value is NOT empty } else { // value is empty }
❌ Check if value is empty
use Aegisora\Rules\Emptiness\EmptyRule; use Aegisora\RuleContract\Models\Context; $result = EmptyRule::create()->validate(Context::create([])); if ($result->isValid()) { // value is empty } else { // value is NOT empty }
🧩 Available Rules
EmptyRule::create(); NotEmptyRule::create();
Both rules:
- accept any value via
Context - return a structured
Result - follow identical validation logic with inverted outcomes
⚠️ Validation Rules
Supported input types:
nullstringarrayintfloatboolobject(with special handling forCountable)
Unsupported types will throw:
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- Value is checked for emptiness
- Result is determined (valid / invalid)
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.