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

Breadcrumb

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

function WordCount::__construct

Parameters

int<0, max>|null $min:

positive-int|null $max:

Overrides Constraint::__construct

File

vendor/symfony/validator/Constraints/WordCount.php, line 37

Class

WordCount
@author Alexandre Daubois <alex.daubois@gmail.com>

Namespace

Symfony\Component\Validator\Constraints

Code

public function __construct(?int $min = null, ?int $max = null, ?string $locale = null, string $minMessage = 'This value is too short. It should contain at least one word.|This value is too short. It should contain at least {{ min }} words.', string $maxMessage = 'This value is too long. It should contain one word.|This value is too long. It should contain {{ max }} words or less.', ?array $groups = null, mixed $payload = null) {
    if (!class_exists(\IntlBreakIterator::class)) {
        throw new \RuntimeException(\sprintf('The "%s" constraint requires the "intl" PHP extension.', __CLASS__));
    }
    if (null === $min && null === $max) {
        throw new MissingOptionsException(\sprintf('Either option "min" or "max" must be given for constraint "%s".', __CLASS__), [
            'min',
            'max',
        ]);
    }
    if (null !== $min && $min <= 0) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the min word count to be a positive integer if set.', __CLASS__));
    }
    if (null !== $max && $max <= 0) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the max word count to be a positive integer if set.', __CLASS__));
    }
    if (null !== $min && null !== $max && $min > $max) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the min word count to be less than or equal to the max word count.', __CLASS__));
    }
    parent::__construct(null, $groups, $payload);
}

API Navigation

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