Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Range.php

function Range::__construct

Parameters

array<string,mixed>|null $options:

string|null $invalidMessage The message if min and max values are numeric but the given value is not:

string|null $invalidDateTimeMessage The message if min and max values are PHP datetimes but the given value is not:

int|float|non-empty-string|null $min The minimum value, either numeric or a datetime string representation:

non-empty-string|null $minPropertyPath Property path to the min value:

int|float|non-empty-string|null $max The maximum value, either numeric or a datetime string representation:

non-empty-string|null $maxPropertyPath Property path to the max value:

string[]|null $groups:

Overrides Constraint::__construct

2 calls to Range::__construct()
RangeConstraint::__construct in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/RangeConstraint.php
Initializes the constraint with options.
RangeConstraint::__construct in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/RangeConstraint.php
Initializes the constraint with options.
1 method overrides Range::__construct()
RangeConstraint::__construct in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/RangeConstraint.php
Initializes the constraint with options.

File

vendor/symfony/validator/Constraints/Range.php, line 60

Class

Range
Validates that a given number or DateTime object is between some minimum and maximum.

Namespace

Symfony\Component\Validator\Constraints

Code

public function __construct(?array $options = null, ?string $notInRangeMessage = null, ?string $minMessage = null, ?string $maxMessage = null, ?string $invalidMessage = null, ?string $invalidDateTimeMessage = null, mixed $min = null, ?string $minPropertyPath = null, mixed $max = null, ?string $maxPropertyPath = null, ?array $groups = null, mixed $payload = null) {
    parent::__construct($options, $groups, $payload);
    $this->notInRangeMessage = $notInRangeMessage ?? $this->notInRangeMessage;
    $this->minMessage = $minMessage ?? $this->minMessage;
    $this->maxMessage = $maxMessage ?? $this->maxMessage;
    $this->invalidMessage = $invalidMessage ?? $this->invalidMessage;
    $this->invalidDateTimeMessage = $invalidDateTimeMessage ?? $this->invalidDateTimeMessage;
    $this->min = $min ?? $this->min;
    $this->minPropertyPath = $minPropertyPath ?? $this->minPropertyPath;
    $this->max = $max ?? $this->max;
    $this->maxPropertyPath = $maxPropertyPath ?? $this->maxPropertyPath;
    if (null === $this->min && null === $this->minPropertyPath && null === $this->max && null === $this->maxPropertyPath) {
        throw new MissingOptionsException(\sprintf('Either option "min", "minPropertyPath", "max" or "maxPropertyPath" must be given for constraint "%s".', __CLASS__), [
            'min',
            'minPropertyPath',
            'max',
            'maxPropertyPath',
        ]);
    }
    if (null !== $this->min && null !== $this->minPropertyPath) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires only one of the "min" or "minPropertyPath" options to be set, not both.', static::class));
    }
    if (null !== $this->max && null !== $this->maxPropertyPath) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires only one of the "max" or "maxPropertyPath" options to be set, not both.', static::class));
    }
    if ((null !== $this->minPropertyPath || null !== $this->maxPropertyPath) && !class_exists(PropertyAccess::class)) {
        throw new LogicException(\sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "minPropertyPath" or "maxPropertyPath" option. Try running "composer require symfony/property-access".', static::class));
    }
    if (null !== $this->min && null !== $this->max && ($minMessage || $maxMessage || isset($options['minMessage']) || isset($options['maxMessage']))) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.', static::class));
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal