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

  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.  */
  24. class UserRole extends ApiEntity
  25. {
  26.     /**
  27.      * @var int
  28.      *
  29.      * @Expose
  30.      */
  31.     protected $id;
  32.     /**
  33.      * @var string
  34.      *
  35.      * @Expose
  36.      */
  37.     protected $locale;
  38.     /**
  39.      * @var UserInterface
  40.      */
  41.     protected $user;
  42.     /**
  43.      * @var RoleInterface
  44.      *
  45.      * @Expose
  46.      */
  47.     protected $role;
  48.     /**
  49.      * Get id.
  50.      *
  51.      * @return int
  52.      */
  53.     public function getId()
  54.     {
  55.         return $this->id;
  56.     }
  57.     /**
  58.      * Set locale.
  59.      *
  60.      * @param string $locale
  61.      *
  62.      * @return UserRole
  63.      */
  64.     public function setLocale($locale)
  65.     {
  66.         $this->locale $locale;
  67.         return $this;
  68.     }
  69.     /**
  70.      * Get locale.
  71.      *
  72.      * @return string
  73.      */
  74.     public function getLocale()
  75.     {
  76.         return $this->locale;
  77.     }
  78.     /**
  79.      * Get Locales as array.
  80.      *
  81.      * @return array
  82.      *
  83.      * @VirtualProperty
  84.      * @SerializedName("locales")
  85.      */
  86.     public function getLocales()
  87.     {
  88.         return \json_decode($this->locale);
  89.     }
  90.     /**
  91.      * Set user.
  92.      *
  93.      * @return UserRole
  94.      */
  95.     public function setUser(UserInterface $user)
  96.     {
  97.         $this->user $user;
  98.         return $this;
  99.     }
  100.     /**
  101.      * Get user.
  102.      *
  103.      * @return UserInterface
  104.      */
  105.     public function getUser()
  106.     {
  107.         return $this->user;
  108.     }
  109.     /**
  110.      * Set role.
  111.      *
  112.      * @return UserRole
  113.      */
  114.     public function setRole(RoleInterface $role)
  115.     {
  116.         if ($role->getAnonymous()) {
  117.             throw new AssignAnonymousRoleException($role);
  118.         }
  119.         $this->role $role;
  120.         return $this;
  121.     }
  122.     /**
  123.      * Get role.
  124.      *
  125.      * @return RoleInterface
  126.      */
  127.     public function getRole()
  128.     {
  129.         return $this->role;
  130.     }
  131. }