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] Adding __toString() method to Role class#10179

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

Conversation

@jameshalsall
Copy link
Contributor

QA
Bug fix?no
New feature?yes
BC breaks?possibly ?
Deprecations?no
Tests pass?yes
Fixed ticketsN/A
LicenseMIT

This PR proposes adding thetoString() method to the\Symfony\Component\Security\Core\Role\Role class. This should ease the comparison of role strings and instances ofRole itself. For example, in theFOSUserBundle theUser model contains roles which are represented as strings. This makes comparisons between arrays ofRole objects and role strings difficult without creating your ownRole class with a__toString(), and this isn't always desirable.

I found some conversation aroundadding the\Seriazable interface to theRole class, and I realise that this might also be considered a BC break if people are relying on the fact that it will not cast to a string.

Copy link
Member

Choose a reason for hiding this comment

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

This will produce a fatal error if$this->role isnull. It is allowed by theRoleInterface.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

good spot, will fix and add a test

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Added tests to ensure that the__toString() behaves as expected, although it was never possible for it to be null because the role was immutable and cast to a string in the constructor

@jameshalsall
Copy link
ContributorAuthor

@fabpot is this okay to be merged?

@Tobion
Copy link
Contributor

It cannot be merged into 2.3. Also the toString doesn't help much when it's not part of the interface. So it would need to be added there as well which makes it a BC break. Could be worth, not sure.

@jameshalsall
Copy link
ContributorAuthor

@Tobion I'm not sure the interface would actually require the__toString() because it's not usually explicitly called? It's there so that PHP knows how to cast it as a string, but isn't really a requirement ofall roles implementing theRoleInterface.

It certainly eases things when you're trying to compare an array ofRole objects and an array of role string names.

@Tobion
Copy link
Contributor

@fabpot@stof should be close this considering the Role and RoleInterface will probably be deprecated according to#11742 ?

@fabpot
Copy link
Member

Closing in favor of what I explained in#8313 (comment)

@fabpotfabpot closed thisFeb 5, 2015
@fabpotfabpot reopened thisFeb 5, 2015
@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.

4 participants

@jameshalsall@Tobion@fabpot@GromNaN

[8]ページ先頭

©2009-2025 Movatter.jp