Skip to content

[Security] Role class magic method to make comparisons easier #10970

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
wants to merge 3 commits into from

Conversation

darektw
Copy link

@darektw darektw commented May 22, 2014

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Now

in_array('ROLE_ADMIN', $user->getRoles())

will work.

I know this can be done with $user->hasRole() method, but consider following:

!!array_intersect(array('ROLE_1', 'ROLE_2'), $user->getRoles())

to check if user has at least one of roles.

…sier.

Now 
```
in_array('ROLE_ADMIN', $user->getRoles())
```
 will work.

I know this can be done with $user->hasRole() method, but consider following:
```
!!array_intersect(array('ROLE_1', 'ROLE_2'), $user->getRoles())
```
to check if user has at least one of roles.
@darektw darektw changed the title [Component][Security][Role] magic method to make comparisons easier [Security] Role class magic method to make comparisons easier May 22, 2014
@darektw
Copy link
Author

darektw commented May 22, 2014

Travis failure is not my fault...

Failed asserting that exception message 'Symfony\Component\Process\Process::setInput only accepts strings.' contains 'Symfony\Component\Process\Process::setStdin only accepts strings.'.

@stof
Copy link
Member

stof commented May 23, 2014

checking if a user has some roles should be done using the security voters, not using hasRole directly (which is meant to be used by the voter layer).
If you call the check on the user directly, the role hierarchy will not be taken into account

@fabpot
Copy link
Member

fabpot commented Feb 5, 2015

closing as a duplicate for #10179

@fabpot fabpot closed this Feb 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants