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.
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.
| Package | Description | Statistics |
|---|---|---|
aegisora/rule-contract |
Defines the core abstractions for building validation rules. | |
aegisora/guardian |
Provides a fluent validation orchestrator for executing rule pipelines. |
| Package | Description | Statistics |
|---|---|---|
aegisora/email-rule |
Validates email values. | |
aegisora/in-array-rule |
Validates that a value exists in a given array. | |
aegisora/instanceof-rule |
Validates object type using instanceof. |
|
aegisora/is-callable-rule |
Validates callable values. | |
aegisora/is-array-rule |
Validates array values. | |
aegisora/boolean-rule |
Validates boolean values. | |
aegisora/emptiness-rule |
Validates empty or non-empty values. | |
aegisora/scalar-equality-rule |
Validates scalar value equality. | |
aegisora/state-transition-rule |
Validates allowed state transitions. |
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. | |
aegisora/email-rule-guardian |
Provides a simple shortcut for email validation. | |
aegisora/in-array-rule-guardian |
Provides a simple shortcut for for in-array value validation. |
Install the core validation orchestrator:
composer require aegisora/guardianInstall individual rules as needed:
composer require aegisora/email-rule
composer require aegisora/is-array-rule
composer require aegisora/in-array-ruleInstall shortcut Rule Guardians when you want simplified application-level validation APIs:
composer require aegisora/instanceof-rule-guardianYou can combine only the packages your application actually needs.
Aegisora rules can be executed directly through rule-contract, composed into validation pipelines through guardian, or wrapped by Rule Guardians for shorter usage.
<?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.
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.
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.
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 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.
Aegisora packages follow a few core principles.
Each rule should validate one specific thing.
This keeps validation logic small, reusable, and easy to test.
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
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.
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.
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.
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.
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
ifchecks 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.
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.
If you discover a security issue, please follow the security policy of the affected repository.
Aegisora packages are open-source and released under the MIT License.
See the LICENSE file in each repository for details.
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.