Skip to content

🛡️ Aegisora

Aegisora is a modular PHP validation ecosystem built around reusable rules, structured validation results, predictable execution flow, and convenient validation shortcuts.

The ecosystem is designed for applications that need validation logic to be:

  • explicit
  • reusable
  • framework-agnostic
  • easy to test
  • easy to compose
  • safe to execute

Aegisora separates validation into small independent packages.

Each rule focuses on one validation concern, Guardian provides a fluent way to execute rule pipelines, and Rule Guardians provide shortcut APIs for common validation scenarios.


🧭 Core Idea

Aegisora follows a simple validation flow:

Value → Context → Rule → Result → Exception or Success

Rules do not return raw booleans.

Instead, every rule receives a Context object and returns a standardized Result object. This makes validation behavior consistent across packages and applications.

For application-level usage, rules can be executed through aegisora/guardian or through specialized shortcut packages called Rule Guardians.


🧩 Ecosystem Packages

⚙️ Core Packages

Package Description Statistics
aegisora/rule-contract Defines the core abstractions for building validation rules. Total Downloads
aegisora/guardian Provides a fluent validation orchestrator for executing rule pipelines. Total Downloads

🧪 Validation Rules

Package Description Statistics
aegisora/email-rule Validates email values. Total Downloads
aegisora/in-array-rule Validates that a value exists in a given array. Total Downloads
aegisora/instanceof-rule Validates object type using instanceof. Total Downloads
aegisora/is-callable-rule Validates callable values. Total Downloads
aegisora/is-array-rule Validates array values. Total Downloads
aegisora/boolean-rule Validates boolean values. Total Downloads
aegisora/emptiness-rule Validates empty or non-empty values. Total Downloads
aegisora/scalar-equality-rule Validates scalar value equality. Total Downloads
aegisora/state-transition-rule Validates allowed state transitions. Total Downloads

🛡️ Rule Guardians

Rule Guardians are shortcut packages built on top of aegisora/guardian and specific validation rules.

They are useful when you want a direct, intention-revealing API without manually creating a rule pipeline every time.

Package Description Statistics
aegisora/instanceof-rule-guardian Provides a shortcut for validating that a value is an instance of a given class. Total Downloads
aegisora/email-rule-guardian Provides a simple shortcut for email validation. Total Downloads
aegisora/in-array-rule-guardian Provides a simple shortcut for for in-array value validation. Total Downloads

📦 Installation

Install the core validation orchestrator:

composer require aegisora/guardian

Install individual rules as needed:

composer require aegisora/email-rule
composer require aegisora/is-array-rule
composer require aegisora/in-array-rule

Install shortcut Rule Guardians when you want simplified application-level validation APIs:

composer require aegisora/instanceof-rule-guardian

You can combine only the packages your application actually needs.


🚀 Example Usage

Aegisora rules can be executed directly through rule-contract, composed into validation pipelines through guardian, or wrapped by Rule Guardians for shorter usage.

Using Guardian Directly

<?php

use Aegisora\Guardian\Guardian;
use Aegisora\Rules\EmailRule;
use App\Exceptions\InvalidEmailException;

$guardian = new Guardian();

$guardian->check(
    'user@example.com',
    EmailRule::create(),
    new InvalidEmailException()
);

For more complex scenarios, multiple rules can be chained together:

<?php

use Aegisora\Guardian\Guardian;
use Aegisora\Rules\EmailRule;
use Aegisora\Rules\EmptinessRule;
use App\Exceptions\EmailIsEmptyException;
use App\Exceptions\InvalidEmailException;

$guardian = new Guardian();

$guardian
    ->that('user@example.com')
    ->must(
        EmptinessRule::notEmpty(),
        new EmailIsEmptyException()
    )
    ->must(
        EmailRule::create(),
        new InvalidEmailException()
    )
    ->validate();

If validation passes, execution continues normally.

If validation fails, Guardian stops on the first failed rule and throws the exception attached to that rule.

Using Rule Guardians

Rule Guardians provide shortcut classes for common validation checks.

<?php

use Aegisora\Guardian\Guardian;
use Aegisora\RuleGuardians\InstanceofRule\InstanceofRuleGuardian;
use Aegisora\RuleGuardians\InstanceofRule\Exceptions\NotInstanceofException;

class User {}

$instanceofRuleGuardian = new InstanceofRuleGuardian(
    new Guardian()
);

try {
    $instanceofRuleGuardian->check(
        new User(),
        User::class
    );

    // value is instance of User
} catch (NotInstanceofException $exception) {
    // value is not instance of User
}

Rule Guardians are especially useful in application services, handlers, controllers, and domain workflows where validation should stay explicit but concise.


📜 Rule Contract

All validation rules are built on top of aegisora/rule-contract.

A rule receives a Context and returns a Result:

<?php

use Aegisora\RuleContract\Models\Context;
use Aegisora\RuleContract\Models\Result;
use Aegisora\RuleContract\Rule;

final class AdultAgeRule extends Rule
{
    protected function executeValidate(Context $context): Result
    {
        $age = $context->getValue();

        if ($age < 18) {
            return Result::invalid('adult_age');
        }

        return Result::valid();
    }
}

This contract keeps all rules predictable and compatible with the rest of the ecosystem.


🛡️ Guardian

aegisora/guardian is the validation execution engine.

It is responsible for:

  • accepting a value
  • creating a validation context
  • executing rules sequentially
  • stopping on the first failed rule
  • throwing default or custom exceptions
  • isolating rule execution errors

Guardian does not contain validation logic itself. Validation logic belongs to independent rule packages.


🧰 Rule Guardians

Rule Guardians are small shortcut packages that combine Guardian with a specific validation rule.

They are not replacements for rules or Guardian. Instead, they provide a simpler API for common checks.

For example, instead of writing:

<?php

$guardian->check(
    $value,
    InstanceofRule::create(User::class),
    new InvalidUserException()
);

a Rule Guardian allows:

<?php

$instanceofRuleGuardian->check(
    $value,
    User::class,
    new InvalidUserException()
);

This keeps application code shorter while preserving the same validation behavior underneath.

Rule Guardians may also provide package-specific exceptions, making validation failures easier to handle in application code.


🧱 Design Principles

Aegisora packages follow a few core principles.

🎯 One Rule — One Responsibility

Each rule should validate one specific thing.

This keeps validation logic small, reusable, and easy to test.

🧰 Framework Agnostic

Aegisora does not depend on Laravel, Symfony, Slim, or any other framework.

Packages can be used in:

  • web applications
  • APIs
  • CLI tools
  • microservices
  • domain-driven projects
  • custom PHP applications

📊 Structured Results

Rules return Result objects instead of raw booleans.

This allows each failed validation to expose a rule code and makes validation failures easier to handle consistently.

🔒 Safe Execution

Unexpected rule execution errors are isolated through the rule contract and can be converted by Guardian into dedicated execution exceptions.

This keeps validation failures separate from rule implementation failures.

🧩 Optional Shortcuts

Rule Guardians are optional shortcut packages.

They exist to make common validation checks more convenient without changing the underlying rule-based architecture.

Applications can use raw rules, Guardian pipelines, Rule Guardians, or any combination of them.


🏷️ Package Naming Convention

Rule packages follow a simple naming convention:

*-rule

Examples:

email-rule
is-array-rule
in-array-rule
instanceof-rule
emptiness-rule
state-transition-rule

Rule Guardian packages follow this naming convention:

*-rule-guardian

Examples:

instanceof-rule-guardian

This makes packages easy to discover and keeps the ecosystem consistent.


🧠 When to Use Aegisora

Aegisora is useful when validation logic needs to be shared across multiple parts of an application or across multiple projects.

Typical use cases:

  • validating DTOs and commands
  • validating API input
  • validating domain values
  • building reusable business rules
  • creating validation pipelines
  • replacing scattered if checks with explicit rules
  • wrapping common validations into convenient shortcut APIs

Use validation rules when you need reusable validation logic.

Use Guardian when you need fluent validation pipelines.

Use Rule Guardians when you want short, intention-revealing validation helpers for frequent checks.


🤝 Contributing

Contributions are welcome.

You can contribute by:

  • reporting issues
  • improving documentation
  • adding tests
  • suggesting new rule packages
  • suggesting new Rule Guardian packages
  • creating new reusable validation rules
  • creating shortcut packages for common validation scenarios

Before contributing, please check the contribution guidelines in the corresponding repository.


🛡️ Security

If you discover a security issue, please follow the security policy of the affected repository.


⚖️ License

Aegisora packages are open-source and released under the MIT License.

See the LICENSE file in each repository for details.


⭐ Support

If you find Aegisora useful, consider giving the repositories a star.

It helps the ecosystem grow and makes the packages easier for other developers to discover.

Pinned Loading

  1. rule-contract rule-contract Public

    Rule Contract defines the core abstractions for building validation rules in the Aegisora ecosystem.

    PHP

  2. guardian guardian Public

    Aegisora Guardian is a lightweight and extensible validation orchestrator for the Aegisora ecosystem. The package provides a fluent and predictable way to execute validation rules against arbitrary…

    PHP

Repositories

Showing 10 of 15 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…