function Length::__construct
Parameters
positive-int|array<string,mixed>|null $exactly The exact expected length:
int<0, max>|null $min The minimum expected length:
positive-int|null $max The maximum expected length:
string|null $charset The charset to be used when computing value's length (defaults to UTF-8):
callable|null $normalizer A callable to normalize value before it is validated:
self::COUNT_*|null $countUnit The character count unit for the length check (defaults to {@see Length::COUNT_CODEPOINTS}):
string[]|null $groups:
array<string,mixed> $options:
Overrides Constraint::__construct
2 calls to Length::__construct()
- LengthConstraint::__construct in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ LengthConstraint.php - Initializes the constraint with options.
- LengthConstraint::__construct in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ LengthConstraint.php - Initializes the constraint with options.
1 method overrides Length::__construct()
- LengthConstraint::__construct in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ LengthConstraint.php - Initializes the constraint with options.
File
-
vendor/
symfony/ validator/ Constraints/ Length.php, line 70
Class
- Length
- Validates that a given string length is between some minimum and maximum value.
Namespace
Symfony\Component\Validator\ConstraintsCode
public function __construct(int|array|null $exactly = null, ?int $min = null, ?int $max = null, ?string $charset = null, ?callable $normalizer = null, ?string $countUnit = null, ?string $exactMessage = null, ?string $minMessage = null, ?string $maxMessage = null, ?string $charsetMessage = null, ?array $groups = null, mixed $payload = null, array $options = []) {
if (\is_array($exactly)) {
$options = array_merge($exactly, $options);
$exactly = $options['value'] ?? null;
}
$min ??= $options['min'] ?? null;
$max ??= $options['max'] ?? null;
unset($options['value'], $options['min'], $options['max']);
if (null !== $exactly && null === $min && null === $max) {
$min = $max = $exactly;
}
parent::__construct($options, $groups, $payload);
$this->min = $min;
$this->max = $max;
$this->charset = $charset ?? $this->charset;
$this->normalizer = $normalizer ?? $this->normalizer;
$this->countUnit = $countUnit ?? $this->countUnit;
$this->exactMessage = $exactMessage ?? $this->exactMessage;
$this->minMessage = $minMessage ?? $this->minMessage;
$this->maxMessage = $maxMessage ?? $this->maxMessage;
$this->charsetMessage = $charsetMessage ?? $this->charsetMessage;
if (null === $this->min && null === $this->max) {
throw new MissingOptionsException(\sprintf('Either option "min" or "max" must be given for constraint "%s".', __CLASS__), [
'min',
'max',
]);
}
if (null !== $this->normalizer && !\is_callable($this->normalizer)) {
throw new InvalidArgumentException(\sprintf('The "normalizer" option must be a valid callable ("%s" given).', get_debug_type($this->normalizer)));
}
if (!\in_array($this->countUnit, self::VALID_COUNT_UNITS, true)) {
throw new InvalidArgumentException(\sprintf('The "countUnit" option must be one of the "%s"::COUNT_* constants ("%s" given).', __CLASS__, $this->countUnit));
}
}