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

Breadcrumb

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

function Cidr::__construct

Overrides Constraint::__construct

File

vendor/symfony/validator/Constraints/Cidr.php, line 77

Class

Cidr
Validates that a value is a valid CIDR notation.

Namespace

Symfony\Component\Validator\Constraints

Code

public function __construct(?array $options = null, ?string $version = null, ?int $netmaskMin = null, ?int $netmaskMax = null, ?string $message = null, ?array $groups = null, $payload = null, ?callable $normalizer = null) {
    $this->version = $version ?? $options['version'] ?? $this->version;
    if (!\array_key_exists($this->version, self::NET_MAXES)) {
        throw new ConstraintDefinitionException(\sprintf('The option "version" must be one of "%s".', implode('", "', array_keys(self::NET_MAXES))));
    }
    $this->netmaskMin = $netmaskMin ?? $options['netmaskMin'] ?? $this->netmaskMin;
    $this->netmaskMax = $netmaskMax ?? $options['netmaskMax'] ?? self::NET_MAXES[$this->version];
    $this->message = $message ?? $this->message;
    $this->normalizer = $normalizer ?? $this->normalizer;
    unset($options['netmaskMin'], $options['netmaskMax'], $options['version']);
    if ($this->netmaskMin < 0 || $this->netmaskMax > self::NET_MAXES[$this->version] || $this->netmaskMin > $this->netmaskMax) {
        throw new ConstraintDefinitionException(\sprintf('The netmask range must be between 0 and %d.', self::NET_MAXES[$this->version]));
    }
    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)));
    }
    parent::__construct($options, $groups, $payload);
}

API Navigation

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