fix: Change the visibility of validation properties for easier inheritance#868
Conversation
|
Hey @sammyskills, I can understand why you want to inherit from Validation? |
|
Hi @datamweb, Yes, before the refactor of the validation rules from PR #861, one could easily customize the rules. But since the rules have now been placed in a class of its own, devs might want to use(reuse) some of the methods in the validation class, to create custom rules (as another way to create or use rules). Take for instance, I have an application that uses login via phone number and password. I can create a validation class in my app/Validations directory, named // app/Validation/ValidationRules.php
use CodeIgniter\Shield\Validation\ValidationRules as ShieldValidationRules;
class ValidationRules extends ShieldValidationRules
{
public function getLoginByPhoneNumberRules(): array
{
return [
'phone' => 'required|numeric',
'password' => $this->getPasswordRules()
]
}
}With the above, the I hope you get what I mean. |
datamweb
left a comment
There was a problem hiding this comment.
Thanks for the explanation,
when I reviewed the #861 I was aware that there would be no limit to customization.
Now I wanted to make sure that there was no limit.
Well, I understand with your explanation, you know that you can create and use your own methods and rules in file app/Config/Validation.php. However, this PR helps the integrity of the code to a great extent.
I think this PR is acceptable.
Yes, I know, and that is what I've been using for a while now. But the PR #861 provides yet another way to set validation rules, for devs who prefer not to use config files. |
|
I'm fine this change if someone wants to extend the class. |
Description
Currently, the
Validationclass declares the properties$configand$tablesas private which makes them impossible to use within child classes. This PR fixes that.Checklist: