Download the PHP package aegisora/in-array-rule-guardian without Composer
On this page you can find all versions of the php package aegisora/in-array-rule-guardian. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/in-array-rule-guardian
More information about aegisora/in-array-rule-guardian
Files in aegisora/in-array-rule-guardian
Package in-array-rule-guardian
Short Description A simple shortcut for in-array value check validation, built on top of aegisora/guardian and aegisora/in-array-rule.
License MIT
Homepage https://github.com/Aegisora/in-array-rule-guardian
Informations about the package in-array-rule-guardian
Aegisora In-Array Rule Guardian
In-Array Rule Guardian provides a simple shortcut for in-array value validation using aegisora/guardian and aegisora/in-array-rule.
It is designed for cases where you want to quickly check whether a value is contained in a given array without manually creating validation pipelines.
This package is built on top of:
โจ Features
- ๐น Simple shortcut API for
InArrayRule - ๐น Validates whether a value is present in an array
- ๐น Supports both strict and soft (loose) comparison
- ๐น Uses
aegisora/guardianinternally - ๐น Uses
aegisora/in-array-ruleinternally - ๐น Supports custom validation exceptions
- ๐น Keeps rule execution errors separated from validation errors
- ๐น Fully compatible with the Aegisora ecosystem
- ๐น Ready to use out of the box
๐ฆ Installation
๐ Core Concept
This package wraps the common validation flow:
into a dedicated shortcut class:
Instead of manually creating InArrayRule and passing it to Guardian, you can use InArrayRuleGuardian directly.
๐๏ธ Basic Usage
โ๏ธ Strict vs Soft Comparison
The package exposes two methods that differ only in how values are compared.
checkStrict()
Uses strict comparison (===). Both the type and the value must match.
checkSoft()
Uses loose comparison (==). Only the value must match after type juggling.
Both methods share the same signature and behaviour regarding exceptions โ only the comparison mode changes.
๐งฉ Usage with Custom Exception
You may provide your own exception for validation failure.
If the value is not present in the array, the provided exception will be thrown.
This is useful when validation errors should have domain-specific meaning.
๐งช Example in Application Service
๐จ Exceptions
This package does not define its own exception types. It delegates execution to Guardian and re-throws the exceptions raised by the underlying pipeline.
GuardianValidationException
Thrown when validation fails and no custom exception is provided.
The rule code for failed in-array validation is in_array_rule.
Custom exception
When a custom exception is passed as the last argument, it is thrown instead of GuardianValidationException on validation failure.
GuardianExecutingRuleException
Thrown when the underlying rule execution fails.
๐งฉ API
InArrayRuleGuardian::checkStrict()
Validates that $value is present in $actualArray using strict comparison (===).
InArrayRuleGuardian::checkSoft()
Validates that $value is present in $actualArray using loose comparison (==).
Parameters (both methods):
$value(mixed) โ value to look for in the array$actualArray(mixed[]) โ array of allowed values (the haystack)$exception(?\Throwable, defaultnull) โ optional custom exception thrown on validation failure
Both methods return void. They communicate results through exceptions only โ they return nothing on success and throw on failure:
GuardianValidationExceptionโ validation failed and no custom exception was provided- the provided custom exception โ validation failed and a custom exception was passed
GuardianExecutingRuleExceptionโ the underlying rule failed to execute
Example:
With custom exception:
๐๏ธ Architecture
This package is a small shortcut layer over the Aegisora validation pipeline.
Flow:
InArrayRuleGuardian::checkStrict()/checkSoft()is calledInArrayRule::createStrict()/InArrayRule::createSoft()is createdGuardianexecutes the rule- If validation succeeds, execution continues normally
- If validation fails, the custom exception or
GuardianValidationExceptionis thrown - If rule execution fails,
GuardianExecutingRuleExceptionis thrown
Internal flow:
๐ Related Packages
- aegisora/guardian โ validation execution orchestrator
- aegisora/in-array-rule โ rule-based in-array validation
- aegisora/rule-contract โ base rule contract and validation result architecture
โ๏ธ 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.