| 1 | <?php |
||
| 22 | final class UserRole |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * The role in plain string. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $role; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Constructor. |
||
| 33 | * |
||
| 34 | * @param string $aRole A role in primitive string |
||
| 35 | * |
||
| 36 | * @throws UserRoleInvalidException when the role is not a string |
||
| 37 | */ |
||
| 38 | public function __construct($aRole) |
||
| 39 | { |
||
| 40 | if (!is_string($aRole)) { |
||
| 41 | throw new UserRoleInvalidException(); |
||
| 42 | } |
||
| 43 | $this->role = $aRole; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Gets the role. |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | public function role() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Method that checks if the user role given is equal to the current. |
||
| 58 | * |
||
| 59 | * @param UserRole $aRole The user role |
||
| 60 | * |
||
| 61 | * @return bool |
||
| 62 | */ |
||
| 63 | public function equals(UserRole $aRole) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Magic method that represents the user role in string format. |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | public function __toString() |
||
| 77 | } |
||
| 78 |