roleScopes = new \Doctrine\Common\Collections\ArrayCollection(); $this->groupCenters = new \Doctrine\Common\Collections\ArrayCollection(); } public function addRoleScope(RoleScope $roleScope) { $this->roleScopes->add($roleScope); } /** * @return string[] */ public function getFlags() { return $this->flags; } /** * @return int */ public function getId() { return $this->id; } /** * @return string */ public function getName() { return $this->name; } /** * @return ArrayCollection|Collection */ public function getRoleScopes() { return $this->roleScopes; } /** * Test that a role scope is associated only once * with the permission group. */ public function isRoleScopePresentOnce(ExecutionContextInterface $context) { $roleScopesId = array_map( static function (RoleScope $roleScope) { return $roleScope->getId(); }, $this->getRoleScopes()->toArray() ); $countedIds = array_count_values($roleScopesId); foreach ($countedIds as $id => $nb) { if (1 < $nb) { $context->buildViolation('A permission is already present ' . 'for the same role and scope') ->addViolation(); } } } /** * @throws RuntimeException if the roleScope could not be removed. */ public function removeRoleScope(RoleScope $roleScope) { $result = $this->roleScopes->removeElement($roleScope); if (false === $result) { throw new RuntimeException(sprintf("The roleScope '%s' could not be removed, " . 'aborting.', spl_object_hash($roleScope))); } } /** * @return $this */ public function setFlags(array $flags) { $this->flags = $flags; return $this; } /** * @param $name * * @return $this */ public function setName($name) { $this->name = $name; return $this; } }