-
-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Description
I have an object with several properties, and I want to write messages for specific paths inside the object.
Example
class FooDto
{
public function __construct(
public \DateTimeImmutable $start,
public \DateTimeImmutable $end,
) {
if ($this->start > $this->end) {
throw new ValidationException('Start date cannot be after end date', 'start');
}
}
}I want this to return:
{
"foo.start": "Start date cannot be after end date"
}This was pretty easy to hack into valinor with a HasPath interface, and:
if ($this->message instanceof HasPath) {
return $this->path . "." . $this->message->path();
}Though it would perhaps also be nice to be able to throw a collection of messages which would be applied for the entire object..
{
"foo.title": "Title cannot be empty when `id` is null"
"foo.start": "Start date cannot be after end date"
}Thoughts?
Metadata
Metadata
Assignees
Labels
No labels