Add Invokable annotations (Trim, Sanitize, MapValue, Between, Regex, Scope, SkipIf) and more#40
Merged
Add Invokable annotations (Trim, Sanitize, MapValue, Between, Regex, Scope, SkipIf) and more#40
Conversation
…m exception message
… and add corresponding tests
…nd add corresponding tests
…y and add corresponding tests
…ith multiple rules and add corresponding tests
…mplement corresponding tests
…d add corresponding tests
…trict mode and add corresponding tests
…rization and add corresponding tests
- Created detailed markdown files for various annotations including #[Cast], #[DefaultValue], #[Explode], #[In], #[MapValue], #[Regex], #[Required], #[Sanitize], #[Scope], #[SkipIf], and #[Trim]. - Each annotation includes sections for parameters, usage examples, behavior, and combining with other attributes. - Updated index.md to include an overview of the Invokable Engine and its features, along with a detailed explanation of the attribute pipeline and lifecycle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a set of method-level PHP Attributes (Annotations) for the Invokable engine to simplify common transformations, validations, and query behaviors inside filter methods.
This PR introduces multiple reusable attributes that reduce boilerplate and make filter logic more declarative and maintainable.
The update also includes documentation for each attribute, an Invokable engine overview, and a test suite covering the new functionality.
Why
Filter methods currently require repetitive code for common operations such as:
These concerns are often cross-cutting, and embedding them inside every filter method increases duplication and reduces readability.
This PR introduces a set of declarative attributes that separate responsibilities into stages:
Benefits:
What changed
1. New Attributes
The following PHP Attributes were added and integrated into the Invokable attributes pipeline.
Control Stage
Attributes that control whether the filter method executes.
Authorize— ensures the filter method is authorized before executionRequired— ensures the payload value is presentSkipIf— conditionally skips the filter method usingPayload is*helpers (supports negation and repeatable usage)Transform Stage
Attributes that modify or normalize incoming values.
Trim— trims whitespace (supportsleft,right, orboth, with optional custom characters)Sanitize— applies sanitization rules such as:Cast— casts the value to a specific type (int, float, bool, string, etc.)Explode— splits a string into an array using a delimiterDefaultValue— assigns a default value when the payload value is missing or emptyMapValue— maps incoming values to different values (supports strict mode)Validate Stage
Attributes responsible for validating incoming values.
Between— numeric range validation (min/max)Regex— validates the value against a regular expressionIn— ensures the value exists within a defined set of allowed valuesBehavior Stage
Attributes that affect the query or business behavior.
Scope— applies an Eloquent scope to the query builder2. Supporting Improvements
Small supporting changes were included to improve:
All changes were kept non-breaking.
Example Usage
Another example:
Migration Notes
Execution order follows the attribute pipeline stages: