mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 11:52:34 +02:00
Do not overwrite method configure()
Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
d85668c359
commit
9c81498395
|
@ -30,17 +30,4 @@ final class DateException extends ValidationException
|
|||
self::STANDARD => '{{name}} must not be a valid date in the format {{sample}}',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configure($name, array $params = [])
|
||||
{
|
||||
$params['sample'] = date(
|
||||
$params['format'],
|
||||
strtotime('2005-12-30')
|
||||
);
|
||||
|
||||
return parent::configure($name, $params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
use function strtotime;
|
||||
|
||||
/**
|
||||
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
||||
* @author Henrique Moody <henriquemoody@gmail.com>
|
||||
|
@ -37,19 +35,6 @@ final class DateTimeException extends ValidationException
|
|||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configure($name, array $params = [])
|
||||
{
|
||||
$params['sample'] = date(
|
||||
(string) $params['format'],
|
||||
strtotime('2005-12-30 01:02:03')
|
||||
);
|
||||
|
||||
return parent::configure($name, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -28,24 +28,6 @@ class IpException extends ValidationException
|
|||
],
|
||||
];
|
||||
|
||||
public function configure($name, array $params = [])
|
||||
{
|
||||
if ($params['networkRange']) {
|
||||
$range = $params['networkRange'];
|
||||
$message = $range['min'];
|
||||
|
||||
if (isset($range['max'])) {
|
||||
$message .= '-'.$range['max'];
|
||||
} else {
|
||||
$message .= '/'.long2ip((int) $range['mask']);
|
||||
}
|
||||
|
||||
$params['range'] = $message;
|
||||
}
|
||||
|
||||
return parent::configure($name, $params);
|
||||
}
|
||||
|
||||
public function chooseTemplate(): string
|
||||
{
|
||||
if (!$this->getParam('networkRange')) {
|
||||
|
|
|
@ -29,17 +29,4 @@ final class TimeException extends ValidationException
|
|||
self::STANDARD => '{{name}} must not be a valid time in the format {{sample}}',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configure($name, array $params = [])
|
||||
{
|
||||
$params['sample'] = date(
|
||||
$params['format'],
|
||||
strtotime('23:59:59')
|
||||
);
|
||||
|
||||
return parent::configure($name, $params);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,11 @@ final class Date extends AbstractRule
|
|||
*/
|
||||
private $format;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sample;
|
||||
|
||||
/**
|
||||
* Initializes the rule.
|
||||
*
|
||||
|
@ -48,6 +53,7 @@ final class Date extends AbstractRule
|
|||
}
|
||||
|
||||
$this->format = $format;
|
||||
$this->sample = date($format, strtotime('2005-12-30'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,11 @@ final class DateTime extends AbstractRule
|
|||
*/
|
||||
private $format;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sample;
|
||||
|
||||
/**
|
||||
* Initializes the rule.
|
||||
*
|
||||
|
@ -40,6 +45,7 @@ final class DateTime extends AbstractRule
|
|||
public function __construct(string $format = null)
|
||||
{
|
||||
$this->format = $format;
|
||||
$this->sample = date($format ?: 'c', strtotime('2005-12-30 01:02:03'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ class Ip extends AbstractRule
|
|||
{
|
||||
public $ipOptions;
|
||||
|
||||
public $range;
|
||||
public $networkRange;
|
||||
|
||||
public function __construct($ipOptions = null)
|
||||
|
@ -30,6 +31,28 @@ class Ip extends AbstractRule
|
|||
}
|
||||
|
||||
$this->networkRange = $this->parseRange($ipOptions);
|
||||
$this->range = $this->createRange();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createRange(): ?string
|
||||
{
|
||||
if (!$this->networkRange) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$range = $this->networkRange;
|
||||
$message = $range['min'];
|
||||
|
||||
if (isset($range['max'])) {
|
||||
$message .= '-'.$range['max'];
|
||||
} else {
|
||||
$message .= '/'.long2ip((int) $range['mask']);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
protected function parseRange($input)
|
||||
|
|
|
@ -33,6 +33,11 @@ final class Time extends AbstractRule
|
|||
*/
|
||||
private $format;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sample;
|
||||
|
||||
/**
|
||||
* Initializes the rule.
|
||||
*
|
||||
|
@ -47,6 +52,7 @@ final class Time extends AbstractRule
|
|||
}
|
||||
|
||||
$this->format = $format;
|
||||
$this->sample = date($format, strtotime('23:59:59'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue