permissions = new ArrayCollection(); } /** * Get the role identifier * * @return int */ public function getId() { return $this->id; } /** * Set the role name * * @param string $name * @return void */ public function setName($name) { $this->name = (string) $name; } /** * Get the role name * * @return string */ public function getName() { return $this->name; } /** * {@inheritDoc} */ public function addPermission($permission) { if (is_string($permission)) { $permission = new Permission($permission); } $this->permissions[(string) $permission] = $permission; } /** * {@inheritDoc} */ public function hasPermission($permission) { // This can be a performance problem if your role has a lot of permissions. Please refer // to the cookbook to an elegant way to solve this issue return isset($this->permissions[(string) $permission]); } }