aegisora/emptiness-rule

Rule-based emptiness validation in Aegisora ecosystem

Maintainers

Package info

github.com/Aegisora/emptiness-rule

pkg:composer/aegisora/emptiness-rule

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-04 17:01 UTC

This package is auto-updated.

Last update: 2026-05-04 17:03:15 UTC


README

Code Coverage Badge Software License PHPStan Badge

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 → Result validation flow
  • 🔹 No raw booleans — only structured results
  • 🔹 Safe execution via base Rule abstraction
  • 🔹 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 Countable with count() === 0

The following are NOT empty:

  • non-empty strings
  • non-empty arrays
  • numbers (int, float)
  • booleans
  • objects (unless Countable and 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:

  • null
  • string
  • array
  • int
  • float
  • bool
  • object (with special handling for Countable)

Unsupported types will throw: Aegisora\RuleContract\Exceptions\InvalidRuleContextException

🏛️ Architecture

This package relies on aegisora/rule-contract (https://github.com/Aegisora/rule-contract).

Validation flow:

  1. validate() is called
  2. Context is passed in
  3. executeValidate() runs
  4. Value is checked for emptiness
  5. Result is determined (valid / invalid)
  6. Result is 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.