Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
darektw wants to merge3 commits intosymfony:masterfromdarektw:patch-1

Conversation

@darektw
Copy link

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets
LicenseMIT
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.
@darektwdarektw changed the title[Component][Security][Role] magic method to make comparisons easier[Security] Role class magic method to make comparisons easierMay 22, 2014
@darektw
Copy link
Author

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

checking if a user has some roles should be done using the security voters, not usinghasRole 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

closing as a duplicate for#10179

@fabpotfabpot closed thisFeb 5, 2015
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@darektw@stof@fabpot

[8]ページ先頭

©2009-2025 Movatter.jp