Instanceof Rule provides a simple, rule-based object type 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.
- 🔹 Lightweight and dependency-free (except rule contract)
- 🔹 Native PHP
instanceofvalidation - 🔹 Fully compatible with Aegisora validation pipeline
- 🔹 Strict
Context → Resultvalidation flow - 🔹 No raw booleans — only structured results
- 🔹 Safe execution via base
Ruleabstraction - 🔹 Simple factory API (
create) - 🔹 Ready to use out of the box
composer require aegisora/instanceof-ruleThis package implements a single validation rule:
- accepts a value via
Context - checks whether it is an instance of a given class
- returns a standardized
Result
Internally uses PHP native operator:
$value instanceof ClassNameuse Aegisora\Rules\InstanceofRule;
use Aegisora\RuleContract\Models\Context;
class User {}
$result = InstanceofRule::create(User::class)->validate(Context::create(new User()));
if ($result->isValid()) {
// value is instance of User
} else {
// value is not instance of User
}InstanceofRule::create($className);$className— fully qualified class name (FQCN)
This package relies on aegisora/rule-contract (https://github.com/Aegisora/rule-contract).
Flow:
validate()is calledContextis passed inexecuteValidate()runsinstanceofcheck is executedResultis returned
All logic is safely handled by Rule contract.
This package is open-source and licensed under the MIT License. See the LICENSE for details.
Contributions are welcome and greatly appreciated!. See the CONTRIBUTING for details.
If you find this project useful, please consider giving it a star on GitHub!
It helps the project grow and motivates further development.