mirror of
https://github.com/Respect/Validation.git
synced 2024-06-04 06:42:22 +02:00
bd63f65c91
This commit will do many different things, but they are all improvements to the "Ip" rules: * Remove passing variables by reference: the "Ip" class uses that a lot to define the start address, end address, and the mask used to validate a network range; * Remove double-typed argument from the constructor: the class "Ip" class has only one argument that can be either a string with the range of the IP or an integer with options for the "filter_var()" function. This commit will split it into two different arguments, each of them used for one of this functionalities; * Update documentation to show how to validate IPv6. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
/**
|
|
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
* @author Danilo Benevides <danilobenevides01@gmail.com>
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
|
*/
|
|
final class IpException extends ValidationException
|
|
{
|
|
public const NETWORK_RANGE = 'network_range';
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public static $defaultTemplates = [
|
|
self::MODE_DEFAULT => [
|
|
self::STANDARD => '{{name}} must be an IP address',
|
|
self::NETWORK_RANGE => '{{name}} must be an IP address in the {{range}} range',
|
|
],
|
|
self::MODE_NEGATIVE => [
|
|
self::STANDARD => '{{name}} must not be an IP address',
|
|
self::NETWORK_RANGE => '{{name}} must not be an IP address in the {{range}} range',
|
|
],
|
|
];
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function chooseTemplate(): string
|
|
{
|
|
if (!$this->getParam('range')) {
|
|
return static::STANDARD;
|
|
}
|
|
|
|
return static::NETWORK_RANGE;
|
|
}
|
|
}
|