Skip to content

[Cookbook][Security] Clarification on the the use of Voter::supportsClass #3702

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

Closed
bystones opened this issue Mar 21, 2014 · 3 comments
Closed
Labels
actionable Clear and specific issues ready for anyone to take them. bug good first issue Ideal for your first contribution! (some Symfony experience may be required) Security

Comments

@bystones
Copy link
Contributor

Hello,
I noticed that the cookbook (http://symfony.com/doc/master/cookbook/security/voters_data_permission.html#creating-the-custom-voter) uses instanceof in the supportsClass method even though the api states that the parameter $class is a string (http://api.symfony.com/master/Symfony/Component/Security/Core/Authorization/Voter/VoterInterface.html#method_supportsClass).
I'm now unsure if the cookbook is wrong and hope you can clarify and/or correct it.

Greetings

@bystones bystones changed the title [Cookbook] Clarification on the the use of Voter::supportsClass [Cookbook][Security] Clarification on the the use of Voter::supportsClass Mar 21, 2014
@bicpi
Copy link
Contributor

bicpi commented Mar 21, 2014

👍 I also noticed this recently.

As PHP does not support scalar type hints it is not possible to force the paramater to be a string. But I think this should be changed as @bystones proposed so that it fits the API instead of passing an object and using instanceof - even if it gives the same result in the end.

@weaverryan
Copy link
Member

Oh yes, that's indeed wrong.

Instead, it should look something like the supportsClass implementation here: http://symfony.com/doc/master/cookbook/security/entity_provider.html#authenticating-someone-with-a-custom-entity-provider

weaverryan added a commit that referenced this issue Mar 24, 2014
… the interface's documentation (xabbuh)

This PR was merged into the 2.3 branch.

Discussion
----------

make method supportsClass() in custom voter compatible with the interface's documentation

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | all
| Fixed tickets | #3702

Commits
-------

36384db make method supportsClass() in custom voter compatible with the interface's documentation
@weaverryan
Copy link
Member

And there was already a PR to fix this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. bug good first issue Ideal for your first contribution! (some Symfony experience may be required) Security
Projects
None yet
Development

No branches or pull requests

3 participants