manager = $manager; $this->security = $security; } protected function supports($attribute, $subject) { return $subject instanceof EntityWorkflow && in_array($attribute, self::getRoles(), true); } /** * @param EntityWorkflow $subject * @param mixed $attribute */ protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool { switch ($attribute) { case self::CREATE: case self::SEE: $handler = $this->manager->getHandler($subject); $entityAttribute = $handler->getRoleShow($subject); if (null === $entityAttribute) { return true; } return $this->security->isGranted($entityAttribute, $handler->getRelatedEntity($subject)); case self::DELETE: return $subject->getStep() === 'initial'; default: throw new UnexpectedValueException("attribute {$attribute} not supported"); } } private static function getRoles(): array { return [ self::SEE, self::CREATE, self::DELETE, ]; } }