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

Breadcrumb

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

class Ip

Validates that a value is a valid IP address.

@author Bernhard Schussek <bschussek@gmail.com> @author Joseph Bielawski <stloyd@gmail.com> @author Ninos Ego <me@ninosego.de>

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\Ip extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of Ip

10 string references to 'Ip'
BanAdmin::submitForm in core/modules/ban/src/Form/BanAdmin.php
Form submission handler.
BanAdmin::validateForm in core/modules/ban/src/Form/BanAdmin.php
Form validation handler.
ban_schema in core/modules/ban/ban.install
Implements hook_schema().
BlockedIp::import in core/modules/ban/src/Plugin/migrate/destination/BlockedIp.php
Import the row.
BlockedIps::query in core/modules/ban/src/Plugin/migrate/source/d7/BlockedIps.php

... See full list

File

vendor/symfony/validator/Constraints/Ip.php, line 25

Namespace

Symfony\Component\Validator\Constraints
View source
class Ip extends Constraint {
    public const V4 = '4';
    public const V6 = '6';
    public const ALL = 'all';
    // adds inverse FILTER_FLAG_NO_RES_RANGE and FILTER_FLAG_NO_PRIV_RANGE flags (skip both)
    public const V4_NO_PUBLIC = '4_no_public';
    public const V6_NO_PUBLIC = '6_no_public';
    public const ALL_NO_PUBLIC = 'all_no_public';
    // adds FILTER_FLAG_NO_PRIV_RANGE flag (skip private ranges)
    public const V4_NO_PRIVATE = '4_no_priv';
    public const V4_NO_PRIV = self::V4_NO_PRIVATE;
    // BC: Alias
    public const V6_NO_PRIVATE = '6_no_priv';
    public const V6_NO_PRIV = self::V6_NO_PRIVATE;
    // BC: Alias
    public const ALL_NO_PRIVATE = 'all_no_priv';
    public const ALL_NO_PRIV = self::ALL_NO_PRIVATE;
    // BC: Alias
    // adds FILTER_FLAG_NO_RES_RANGE flag (skip reserved ranges)
    public const V4_NO_RESERVED = '4_no_res';
    public const V4_NO_RES = self::V4_NO_RESERVED;
    // BC: Alias
    public const V6_NO_RESERVED = '6_no_res';
    public const V6_NO_RES = self::V6_NO_RESERVED;
    // BC: Alias
    public const ALL_NO_RESERVED = 'all_no_res';
    public const ALL_NO_RES = self::ALL_NO_RESERVED;
    // BC: Alias
    // adds FILTER_FLAG_NO_PRIV_RANGE and FILTER_FLAG_NO_RES_RANGE flags (skip both)
    public const V4_ONLY_PUBLIC = '4_public';
    public const V6_ONLY_PUBLIC = '6_public';
    public const ALL_ONLY_PUBLIC = 'all_public';
    // adds inverse FILTER_FLAG_NO_PRIV_RANGE
    public const V4_ONLY_PRIVATE = '4_private';
    public const V6_ONLY_PRIVATE = '6_private';
    public const ALL_ONLY_PRIVATE = 'all_private';
    // adds inverse FILTER_FLAG_NO_RES_RANGE
    public const V4_ONLY_RESERVED = '4_reserved';
    public const V6_ONLY_RESERVED = '6_reserved';
    public const ALL_ONLY_RESERVED = 'all_reserved';
    public const INVALID_IP_ERROR = 'b1b427ae-9f6f-41b0-aa9b-84511fbb3c5b';
    protected const VERSIONS = [
        self::V4,
        self::V6,
        self::ALL,
        self::V4_NO_PUBLIC,
        self::V6_NO_PUBLIC,
        self::ALL_NO_PUBLIC,
        self::V4_NO_PRIVATE,
        self::V6_NO_PRIVATE,
        self::ALL_NO_PRIVATE,
        self::V4_NO_RESERVED,
        self::V6_NO_RESERVED,
        self::ALL_NO_RESERVED,
        self::V4_ONLY_PUBLIC,
        self::V6_ONLY_PUBLIC,
        self::ALL_ONLY_PUBLIC,
        self::V4_ONLY_PRIVATE,
        self::V6_ONLY_PRIVATE,
        self::ALL_ONLY_PRIVATE,
        self::V4_ONLY_RESERVED,
        self::V6_ONLY_RESERVED,
        self::ALL_ONLY_RESERVED,
    ];
    protected const ERROR_NAMES = [
        self::INVALID_IP_ERROR => 'INVALID_IP_ERROR',
    ];
    public string $version = self::V4;
    public string $message = 'This is not a valid IP address.';
    
    /** @var callable|null */
    public $normalizer;
    
    /**
     * @param array<string,mixed>|null            $options
     * @param self::V4*|self::V6*|self::ALL*|null $version The IP version to validate (defaults to {@see self::V4})
     * @param string[]|null                       $groups
     */
    public function __construct(?array $options = null, ?string $version = null, ?string $message = null, ?callable $normalizer = null, ?array $groups = null, mixed $payload = null) {
        parent::__construct($options, $groups, $payload);
        $this->version = $version ?? $this->version;
        $this->message = $message ?? $this->message;
        $this->normalizer = $normalizer ?? $this->normalizer;
        if (!\in_array($this->version, static::VERSIONS, true)) {
            throw new ConstraintDefinitionException(\sprintf('The option "version" must be one of "%s".', implode('", "', static::VERSIONS)));
        }
        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)));
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Constraint::$groups public property The groups that the constraint belongs to.
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 2
Constraint::CLASS_CONSTRAINT public constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP public constant The name of the group given to all constraints with no explicit group.
Constraint::getDefaultOption public function Returns the name of the default option. 28
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getRequiredOptions public function Returns the name of the required options. 22
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or
both.
8
Constraint::normalizeOptions protected function
Constraint::PROPERTY_CONSTRAINT public constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 9
Constraint::__get public function Returns the value of a lazily initialized option. 2
Constraint::__isset public function 1
Constraint::__set public function Sets the value of a lazily initialized option. 1
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
Ip::$message public property
Ip::$normalizer public property @var callable|null
Ip::$version public property
Ip::ALL public constant
Ip::ALL_NO_PRIV public constant
Ip::ALL_NO_PRIVATE public constant
Ip::ALL_NO_PUBLIC public constant
Ip::ALL_NO_RES public constant
Ip::ALL_NO_RESERVED public constant
Ip::ALL_ONLY_PRIVATE public constant
Ip::ALL_ONLY_PUBLIC public constant
Ip::ALL_ONLY_RESERVED public constant
Ip::ERROR_NAMES protected constant Maps error codes to the names of their constants. Overrides Constraint::ERROR_NAMES
Ip::INVALID_IP_ERROR public constant
Ip::V4 public constant
Ip::V4_NO_PRIV public constant
Ip::V4_NO_PRIVATE public constant
Ip::V4_NO_PUBLIC public constant
Ip::V4_NO_RES public constant
Ip::V4_NO_RESERVED public constant
Ip::V4_ONLY_PRIVATE public constant
Ip::V4_ONLY_PUBLIC public constant
Ip::V4_ONLY_RESERVED public constant
Ip::V6 public constant
Ip::V6_NO_PRIV public constant
Ip::V6_NO_PRIVATE public constant
Ip::V6_NO_PUBLIC public constant
Ip::V6_NO_RES public constant
Ip::V6_NO_RESERVED public constant
Ip::V6_ONLY_PRIVATE public constant
Ip::V6_ONLY_PUBLIC public constant
Ip::V6_ONLY_RESERVED public constant
Ip::VERSIONS protected constant
Ip::__construct public function Overrides Constraint::__construct
RSS feed
Powered by Drupal