Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to improve describing property paths #324

Open
arjanfrans opened this issue Apr 6, 2022 · 0 comments
Open

API to improve describing property paths #324

arjanfrans opened this issue Apr 6, 2022 · 0 comments

Comments

@arjanfrans
Copy link

arjanfrans commented Apr 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant