aegisora/in-array-rule

Rule-based in-array validation in Aegisora ecosystem

Maintainers

Package info

github.com/Aegisora/in-array-rule

pkg:composer/aegisora/in-array-rule

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-04-29 16:52 UTC

This package is auto-updated.

Last update: 2026-04-29 17:00:55 UTC


README

Code Coverage Badge Software License PHPStan Badge

In-Array Rule provides a simple, rule-based array membership 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 dependency-free (except rule contract)
  • 🔹 Strict and soft comparison modes (in_array behavior)
  • 🔹 Fully compatible with Aegisora validation pipeline
  • 🔹 Strict Context → Result validation flow
  • 🔹 No raw booleans — only structured results
  • 🔹 Safe execution via base Rule abstraction
  • 🔹 Simple factory API (create, createStrict, createSoft)
  • 🔹 Ready to use out of the box

📦 Installation

composer require aegisora/in-array-rule

🚀 Core Concept

This package implements a single validation rule:

  • accepts a value via Context
  • checks whether it exists in a predefined array
  • returns a standardized Result

Internally uses PHP native function:

in_array($value, $array, $strict)

🏗️ Basic Usage

use Aegisora\Rules\InArrayRule;
use Aegisora\RuleContract\Models\Context;

$rule = InArrayRule::create(['apple', 'banana', 'orange',]);

$result = $rule->validate(Context::create('banana'));

if ($result->isValid()) {
    // value exists in array
} else {
    // value not found
}

🔒 Strict vs Soft Mode

Strict mode (default)

$rule = InArrayRule::create([1, 2, 3,]);

$rule->validate(Context::create('1')); // false

Strict comparison checks type as well.

Soft mode

$rule = InArrayRule::createSoft([1, 2, 3,]);

$rule->validate(Context::create('1')); // true

Allows loose comparison (== behavior).

🧩 Factory Methods

InArrayRule::create($array);         // strict by default
InArrayRule::createStrict($array);   // explicit strict
InArrayRule::createSoft($array);     // loose comparison

🏛️ Architecture

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

Flow:

  1. validate() is called
  2. Context is passed in
  3. executeValidate() runs
  4. in_array check is executed
  5. Result is returned

All logic is safely handled by Rule contract.

⚖️ 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.