authorizationHelper = $authorizationHelper; } protected function supports($attribute, $subject) { if ($subject instanceof ThirdParty) { return \in_array($attribute, $this->getRoles()); } elseif ($subject === NULL) { return $attribute === self::CREATE || $attribute === self::SHOW ; } return false; } /** * * @param string $attribute * @param ThirdParty|null $subject * @param TokenInterface $token * @return type */ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { return true; $user = $token->getUser(); if (!$user instanceof User) { return false; } return true; $centers = $this->authorizationHelper ->getReachableCenters($user, new Role($attribute)); if ($subject === NULL) { return count($centers) > 0; } elseif ($subject instanceof ThirdParty) { return count(\array_intersect($centers, $subject->getCenters()->toArray())) > 0; } return false; } public function getRoles(): array { return [ self::CREATE, self::UPDATE, self::SHOW ]; } public function getRolesWithHierarchy(): array { return [ 'Third Party' => $this->getRoles() ]; } public function getRolesWithoutScope(): array { return $this->getRoles(); } }