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

Validator extender #2102

Merged
merged 9 commits into from Nov 1, 2020
Merged

Conversation

askvortsov1
Copy link
Sponsor Member

Fixes part of #1891

Changes proposed in this pull request:

  • Add Validator extender with configure method
  • Add integration tests
  • Deprecate Validating event

Reviewers should focus on:
I slightly deviated from the previously discussed spec on this one, as I think that having a configure method that runs the validator through a callable gives us and developers more flexibility than simply the ability to add rules. Similarly, there are extensions that depend on this type of capabilities.

Should there be a dedicated method to run the ruleset through a callable as well? I'm not sure if that is necessary (this PR supports that), but it might be a nice shortcut.

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

@franzliedke franzliedke mentioned this pull request Apr 13, 2020
78 tasks
@franzliedke
Copy link
Contributor

Similarly, there are extensions that depend on this type of capabilities.

Could you provide a few examples / links? It's hard to think about this in the abstract.

@askvortsov1
Copy link
Sponsor Member Author

@stale
Copy link

stale bot commented Oct 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We do this to keep the amount of open issues to a manageable minimum.
In any case, thanks for taking an interest in this software and contributing by opening the issue in the first place!

@stale stale bot added the stale Issues that have had over 90 days of inactivity label Oct 9, 2020
@askvortsov1
Copy link
Sponsor Member Author

Not stale

@stale stale bot removed the stale Issues that have had over 90 days of inactivity label Oct 9, 2020
@askvortsov1 askvortsov1 added this to the 0.1.0-beta.15 milestone Oct 21, 2020
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deprecation messages will need to be updated (beta13 => beta14)

Regarding the code of the test, I'm not sure whether we want to explain what it does or simplify it? I believe it's copied from one of my example and the reason it's so complex is to keep the additional password rules that might have been made by other extensions. I think having a comment reminding that would be useful for future readers.

Or we could also use a shorter code that blindly replaces the rules without regard for other extensions. This might be something legitimately used in the local extend.php when the list of extensions is well known. Something like: (untested)

        $this->extend((new Extend\Validator(UserValidator::class))->configure(function ($validator) {
                $validator->setRules([
                    'password' => [
                        'required',
                        'min:8'
                    ]
                ] + $validator->getRules());
            }
        }));

I think it would still make sense to pass the Flarum validator object to the callback. It could be the second param instead of the first like it was with the event. Sometimes values are stored on that object, for example the user instance on UserValidator.

There's also the not-exactly-related-but-somewhat-close matter of #2398 where an event might or might not make sense (?)

@askvortsov1 askvortsov1 self-assigned this Oct 28, 2020
- Provide both flarum and laravel validator to validator configure extender
- Simplify integration test example
- Add integration test with invokable class.
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested locally, but this looks good 👍

Should the tests cover calling a callback/class that takes a single argument? This is something that should work in PHP? One of the two (callback or class) could omit the second argument on purpose (with a comment explaining it's omitted)

@askvortsov1 askvortsov1 merged commit 5842dd1 into flarum:master Nov 1, 2020
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

Successfully merging this pull request may close these issues.

None yet

4 participants