This commit is contained in:
2023-12-18 18:24:39 +08:00
parent 271e481035
commit 6621c5f247
3 changed files with 13 additions and 17 deletions
+4 -9
View File
@@ -34,18 +34,13 @@ abstract class BaseValidator
/**
* @param $field
* @param $message
* @param string $field
* @param string $message
* @return bool
*/
public function addError($field, $message): bool
public function addError(string $field, string $message): bool
{
if (!is_null($field)) {
$message = str_replace(':attribute', $field, $message);
}
$this->message = $message;
$this->message = str_replace(':attribute', $field, $message);
return false;
}
+8 -8
View File
@@ -38,46 +38,46 @@ class DateTimeValidator extends BaseValidator
}
/**
* @param $value
* @param string $value
* @return bool
*
* 效验分秒 格式如 01:02 or 01-02
*/
public function validatorTime($value): bool
public function validatorTime(string $value): bool
{
return (bool)preg_match('/^\d{2}:\d{2}(:\d{2})?+(\.\d+)?$/', $value);
}
/**
* @param $value
* @param string $value
* @return bool
*
* 效验分秒 格式如 2017-12-22 01:02
*/
public function validateDatetime($value): bool
public function validateDatetime(string $value): bool
{
return (bool)preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?+(\.\d+)?$/', $value);
}
/**
* @param $value
* @param string $value
* @return bool
*
* 效验分秒 格式如 2017-12-22
*/
public function validatorDate($value): bool
public function validatorDate(string $value): bool
{
return (bool)preg_match('/^\d{4}-\d{2}-\d{2}$/', $value);
}
/**
* @param $value
* @param string|int $value
* @return bool
*
* 效验时间戳 格式如 1521452254
*/
public function validatorTimestamp($value): bool
public function validatorTimestamp(string|int $value): bool
{
return (bool)preg_match('/^1\d{9}$/', $value);
}
+1
View File
@@ -92,6 +92,7 @@ class Validator extends BaseValidator
return [Kiri::createObject($defined), 'trigger'];
}
/**
* @param ModelInterface $model
* @return bool