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?
I have an object with several properties, and I want to write messages for specific paths inside the object.
Example
I want this to return:
{ "foo.start": "Start date cannot be after end date" }This was pretty easy to hack into valinor with a
HasPathinterface, and: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?