Introduce ErrorsAware interface and a base trait implementation
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 167
- Forks
- 47
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 3
Description
ErrorsAwareInterface is a marker same as PostValidationHookInterface.
It may set all errors after validation into an validated object. It may unify forms and request-model.
interface ErrorsAwareInterface {
public function addError(string $attribute): void;
public function getError(string $attribute): mixed; <-- either Stringable or Stringable[]
public function hasError(string $attribute): bool;
public function setErrors(array $errorsMap): void;
public function getErrors(): array;
public function hasErrors(): bool;
}
So the base trait should implement all of these methods;
Usage is simple:
$validator->validate($object);
if ($object->hasErrors()) {
// ...
}
Instead of
$result = $validator->validate($object);
if ($result->hasErrors()) {
// ...
}
It may be useful with nested structures that may be hard accessible and just a shortcut to pass both errors and the object somewhere together.
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
Start by reading src/PostValidationHookInterface.php, which the issue identifies as the model for the marker interface. Then clarify how the proposed ErrorsAwareInterface and base trait should represent individual and mapped errors, including the Stringable-or-array return case. Done means the interface and trait provide all listed methods and support the validator usage shown in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100