10000 [Security] Adding __toString() method to Role class by jameshalsall · Pull Request #10179 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[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 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 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Security] Adding __toString() method to Role class
  • Loading branch information
jameshalsall committed Feb 2, 2014
commit a5b15dc1e37bdaf0276edd78769e100bef0d37f6
10 changes: 10 additions & 0 deletions src/Symfony/Component/Security/Core/Role/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ public function getRole()
{
return $this->role;
}

/**
* Returns a string representation of the role
*
* @return string
*/
public function __toString()
{
return $this->role;
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 is null. It is allowed by the RoleInterface.

Copy link
Contributor Author

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
Contributor Author

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

}
}
0