roles = new ArrayCollection(); } public function getIdentity(): Identity { return $this->identity; } public function setIdentity(Identity $identity): static { $this->identity = $identity; $identity->addProfile($this); return $this; } /** * @return AclRole[] */ public function getRoles(): array { return $this->roles->toArray(); } public function addRole(AclRole $role): static { if ($this->roles->contains($role)) { return $this; } $this->roles->add($role); return $this; } public function isAllowed(Resource $resource): bool { foreach ($this->getRoles() as $_role) { if ($_role->getIsAdmin()) { return true; } if (array_any($_role->getResources(), fn($_resource) => $_resource->getName() === $resource->getResourceId())) { return true; } } return false; } public function getAccount(): Account { return $this->account; } public function setAccount(Account $account): static { $this->account = $account; return $this; } }