Skip to content

API to improve describing property paths #324

@arjanfrans

Description

@arjanfrans

I am using validation in my models and want to be specific about the validation errors. I want to know from which class and property and error came. I am aware that it is possible by setting the 'defaultPropertyPath' to something like 'Address.street', but this will cause a lot of duplication. For each 'that' call you'd have to specify the property.

What I am looking for is an API which looks more like this:

Assert::lazy('Address')
            ->that($street, 'street')->notEmpty()
            ->that($number, 'number')->notEmpty()
            ->verifyNow();
Assert::that('Address', 'street')->notEmpty();

For the "root" it might also be a nice idea to add a 'getRootPath' function that can be overriden. So that someone can pass in $this or $something::class and then format it inside this function, for example: reading $this::class and stripping it down to the basename.

I already have an implementation for this. Of course, to be backwards compatible it would mean that the that function can not be used; so maybe a new function called thatProperty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions