children = new ArrayCollection(); $this->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 addChild(HierarchicalRoleInterface $child) { $this->children[] = $child; } /** * {@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]); } /** * {@inheritDoc} */ public function getChildren() { return $this->children; } /** * {@inheritDoc} */ public function hasChildren() { return !$this->children->isEmpty(); } }