. */ declare(strict_types=1); namespace App\Validator\Constraints; use App\Security\Interfaces\HasPermissionsInterface; use App\Services\UserSystem\PermissionManager; use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; class ValidPermissionValidator extends ConstraintValidator { protected PermissionManager $resolver; protected array $perm_structure; public function __construct(PermissionManager $resolver) { $this->resolver = $resolver; } /** * Checks if the passed value is valid. * * @param mixed $value The value that should be validated * @param Constraint $constraint The constraint for the validation */ public function validate($value, Constraint $constraint): void { if (!$constraint instanceof ValidPermission) { throw new UnexpectedTypeException($constraint, ValidPermission::class); } /** @var HasPermissionsInterface $perm_holder */ $perm_holder = $this->context->getObject(); $this->resolver->ensureCorrectSetOperations($perm_holder); } }