Repository navigation
Validate grant types - #14
Conversation
|
Whoops, let me go back and answer :) |
rmccue
left a comment
There was a problem hiding this comment.
Could we instead just specify function ( Type $type ) and have PHP validate for us? 🤔
| $grant_types = apply_filters( 'oauth2.grant_types', array() ); | ||
|
|
||
| return array_filter( $grant_types, function ( $type ) { | ||
|
|
There was a problem hiding this comment.
Removed (aka fixed).
No, not really. PHP would not validate (and discard invalid) types, like the code that I suggested, but rather expect correct implementations, and fatal error if encountered anything else. return array_filter( $types, function ( Type $type ) {
return true;
} );So, in fact, we wouldn't really need the callback('s body), but just PHP that kicks in for checking (and fatal erroring because of) the type. To be honest, I would rather keep my code (or something along the lines). But like I said, the bahavior would be discard invalid types. If you want PHP to jump the user into their face, we can do that. 😀 Does this make sense? 🤔 |
|
I'd rather not silently drop objects; it makes debugging a pain for developers. If not the fatal error, we should at least fire a |
|
Makes sense. Should I adapt the closure accordingly? |
|
That'd be great, thanks :) |
Inform user when they are doing it wrong. Since it is PHP 5.6, we cannot use array_filter() with the ARRAY_FILTER_USE_BOTH flag, can we? Thus, use a regular foreach loop.
|
I just updated the validation code, again. If only we could use PHP 5.6+... :) Comments? |
Hi again,
@rmccue didn't comment on my What's Left list in #8, but since this was no big deal, I just created this pull request with a proposed validation for grant type( handler)s.
The result of the grant type filter,
oauth2.grant_types, will be validated, and onlyWP\OAuth2\Types\Typeimplementations make it to the consumer.Comments?
Cheers,
Thorsten