vendor/sulu/sulu/src/Sulu/Bundle/SecurityBundle/Entity/UserRole.php line 27

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of Sulu.
  4. *
  5. * (c) Sulu GmbH
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Sulu\Bundle\SecurityBundle\Entity;
  11. use JMS\Serializer\Annotation\ExclusionPolicy;
  12. use JMS\Serializer\Annotation\Expose;
  13. use JMS\Serializer\Annotation\SerializedName;
  14. use JMS\Serializer\Annotation\VirtualProperty;
  15. use Sulu\Bundle\CoreBundle\Entity\ApiEntity;
  16. use Sulu\Bundle\SecurityBundle\Exception\AssignAnonymousRoleException;
  17. use Sulu\Component\Security\Authentication\RoleInterface;
  18. use Sulu\Component\Security\Authentication\UserInterface;
  19. /**
  20. * UserRole.
  21. */
  22. #[ExclusionPolicy('all')] // ;
  23. class UserRole extends ApiEntity
  24. {
  25. /**
  26. * @var int
  27. */
  28. #[Expose]
  29. protected $id;
  30. /**
  31. * @var string
  32. */
  33. #[Expose]
  34. protected $locale;
  35. /**
  36. * @var UserInterface
  37. */
  38. protected $user;
  39. /**
  40. * @var RoleInterface
  41. */
  42. #[Expose]
  43. protected $role;
  44. /**
  45. * Get id.
  46. *
  47. * @return int
  48. */
  49. public function getId()
  50. {
  51. return $this->id;
  52. }
  53. /**
  54. * Set locale.
  55. *
  56. * @param string $locale
  57. *
  58. * @return UserRole
  59. */
  60. public function setLocale($locale)
  61. {
  62. $this->locale = $locale;
  63. return $this;
  64. }
  65. /**
  66. * Get locale.
  67. *
  68. * @return string
  69. */
  70. public function getLocale()
  71. {
  72. return $this->locale;
  73. }
  74. /**
  75. * Get Locales as array.
  76. *
  77. * @return array
  78. */
  79. #[VirtualProperty]
  80. #[SerializedName('locales')]
  81. public function getLocales()
  82. {
  83. return \json_decode($this->locale);
  84. }
  85. /**
  86. * Set user.
  87. *
  88. * @return UserRole
  89. */
  90. public function setUser(UserInterface $user)
  91. {
  92. $this->user = $user;
  93. return $this;
  94. }
  95. /**
  96. * Get user.
  97. *
  98. * @return UserInterface
  99. */
  100. public function getUser()
  101. {
  102. return $this->user;
  103. }
  104. /**
  105. * Set role.
  106. *
  107. * @return UserRole
  108. */
  109. public function setRole(RoleInterface $role)
  110. {
  111. if ($role->getAnonymous()) {
  112. throw new AssignAnonymousRoleException($role);
  113. }
  114. $this->role = $role;
  115. return $this;
  116. }
  117. /**
  118. * Get role.
  119. *
  120. * @return RoleInterface
  121. */
  122. public function getRole()
  123. {
  124. return $this->role;
  125. }
  126. }