getPrecedingConstraints example

/** * Checks whether any preceding constraints have been violated. * * @param \Symfony\Component\Validator\Constraint $current_constraint * The constraint currently being validated. * * @return bool * TRUE if any preceding constraints have been violated, FALSE otherwise. */
  protected function hasViolationsForPrecedingConstraints(Constraint $current_constraint): bool {
    assert($this->context instanceof ExecutionContext);
    $earlier_constraints = iterator_to_array($this->getPrecedingConstraints($current_constraint));
    $earlier_violations = array_filter(
      iterator_to_array($this->context->getViolations()),
      function DConstraintViolationInterface $violation) use ($earlier_constraints) {
        return in_array($violation->getConstraint()$earlier_constraints);
      }
    );
    return !empty($earlier_violations);
  }

  /** * Gets the constraints preceding the given constraint in the current context. * * @param \Symfony\Component\Validator\Constraint $needle * The constraint to find the preceding constraints for. * * @return iterable * The preceding constraints. */
Home | Imprint | This part of the site doesn't use cookies.