Callable rule attribute interface
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 167
- Forks
- 47
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 3
Description
Callable rule class may look like this:
final class MyRule {
public function __invoke(mixed $value, object $rule, ValidationContext $context): Result {
// ...
}
}
For simple custom rules is good solution, but there is one problem. It is not possible usage as attribute.
We can add attribute Attribute:
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
final class MyRule {
// ...
It's not enough, because validator parse attributes that implement RuleInterface only.
Suggest add new interface CallableRuleAttributeInterface and parse implementing its attributes in addition to RuleInterface.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests. Start by tracing the validator's attribute parsing and its checks for RuleInterface, then review the callable rule shape shown in the issue. Done means callable rule attributes are recognized alongside RuleInterface attributes, including the proposed repeatable class and property usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100