Upgrade to 3.7.1

This commit is contained in:
Bastian Allgeier
2022-07-12 13:33:21 +02:00
parent 7931eb5e47
commit 1ad1eaf387
377 changed files with 63981 additions and 63824 deletions

View File

@@ -16,279 +16,279 @@ use Kirby\Toolkit\V;
*/
class Validations
{
/**
* Validates if the field value is boolean
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function boolean($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (is_bool($value) === false) {
throw new InvalidArgumentException([
'key' => 'validation.boolean'
]);
}
}
/**
* Validates if the field value is boolean
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function boolean($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (is_bool($value) === false) {
throw new InvalidArgumentException([
'key' => 'validation.boolean'
]);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is valid date
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function date($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::date($value) !== true) {
throw new InvalidArgumentException(
V::message('date', $value)
);
}
}
/**
* Validates if the field value is valid date
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function date($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::date($value) !== true) {
throw new InvalidArgumentException(
V::message('date', $value)
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is valid email
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function email($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::email($value) === false) {
throw new InvalidArgumentException(
V::message('email', $value)
);
}
}
/**
* Validates if the field value is valid email
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function email($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::email($value) === false) {
throw new InvalidArgumentException(
V::message('email', $value)
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is maximum
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function max($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->max() !== null) {
if (V::max($value, $field->max()) === false) {
throw new InvalidArgumentException(
V::message('max', $value, $field->max())
);
}
}
/**
* Validates if the field value is maximum
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function max($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->max() !== null) {
if (V::max($value, $field->max()) === false) {
throw new InvalidArgumentException(
V::message('max', $value, $field->max())
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is max length
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function maxlength($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->maxlength() !== null) {
if (V::maxLength($value, $field->maxlength()) === false) {
throw new InvalidArgumentException(
V::message('maxlength', $value, $field->maxlength())
);
}
}
/**
* Validates if the field value is max length
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function maxlength($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->maxlength() !== null) {
if (V::maxLength($value, $field->maxlength()) === false) {
throw new InvalidArgumentException(
V::message('maxlength', $value, $field->maxlength())
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is minimum
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function min($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->min() !== null) {
if (V::min($value, $field->min()) === false) {
throw new InvalidArgumentException(
V::message('min', $value, $field->min())
);
}
}
/**
* Validates if the field value is minimum
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function min($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->min() !== null) {
if (V::min($value, $field->min()) === false) {
throw new InvalidArgumentException(
V::message('min', $value, $field->min())
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is min length
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function minlength($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->minlength() !== null) {
if (V::minLength($value, $field->minlength()) === false) {
throw new InvalidArgumentException(
V::message('minlength', $value, $field->minlength())
);
}
}
/**
* Validates if the field value is min length
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function minlength($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->minlength() !== null) {
if (V::minLength($value, $field->minlength()) === false) {
throw new InvalidArgumentException(
V::message('minlength', $value, $field->minlength())
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value matches defined pattern
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function pattern($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->pattern() !== null) {
if (V::match($value, '/' . $field->pattern() . '/i') === false) {
throw new InvalidArgumentException(
V::message('match')
);
}
}
/**
* Validates if the field value matches defined pattern
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function pattern($field, $value): bool
{
if ($field->isEmpty($value) === false && $field->pattern() !== null) {
if (V::match($value, '/' . $field->pattern() . '/i') === false) {
throw new InvalidArgumentException(
V::message('match')
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is required
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function required($field, $value): bool
{
if ($field->isRequired() === true && $field->save() === true && $field->isEmpty($value) === true) {
throw new InvalidArgumentException([
'key' => 'validation.required'
]);
}
/**
* Validates if the field value is required
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function required($field, $value): bool
{
if ($field->isRequired() === true && $field->save() === true && $field->isEmpty($value) === true) {
throw new InvalidArgumentException([
'key' => 'validation.required'
]);
}
return true;
}
return true;
}
/**
* Validates if the field value is in defined options
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function option($field, $value): bool
{
if ($field->isEmpty($value) === false) {
$values = array_column($field->options(), 'value');
/**
* Validates if the field value is in defined options
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function option($field, $value): bool
{
if ($field->isEmpty($value) === false) {
$values = array_column($field->options(), 'value');
if (in_array($value, $values, true) !== true) {
throw new InvalidArgumentException([
'key' => 'validation.option'
]);
}
}
if (in_array($value, $values, true) !== true) {
throw new InvalidArgumentException([
'key' => 'validation.option'
]);
}
}
return true;
}
return true;
}
/**
* Validates if the field values is in defined options
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function options($field, $value): bool
{
if ($field->isEmpty($value) === false) {
$values = array_column($field->options(), 'value');
foreach ($value as $val) {
if (in_array($val, $values, true) === false) {
throw new InvalidArgumentException([
'key' => 'validation.option'
]);
}
}
}
/**
* Validates if the field values is in defined options
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function options($field, $value): bool
{
if ($field->isEmpty($value) === false) {
$values = array_column($field->options(), 'value');
foreach ($value as $val) {
if (in_array($val, $values, true) === false) {
throw new InvalidArgumentException([
'key' => 'validation.option'
]);
}
}
}
return true;
}
return true;
}
/**
* Validates if the field value is valid time
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function time($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::time($value) !== true) {
throw new InvalidArgumentException(
V::message('time', $value)
);
}
}
/**
* Validates if the field value is valid time
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function time($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::time($value) !== true) {
throw new InvalidArgumentException(
V::message('time', $value)
);
}
}
return true;
}
return true;
}
/**
* Validates if the field value is valid url
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function url($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::url($value) === false) {
throw new InvalidArgumentException(
V::message('url', $value)
);
}
}
/**
* Validates if the field value is valid url
*
* @param \Kirby\Form\Field|\Kirby\Form\FieldClass $field
* @param $value
* @return bool
* @throws \Kirby\Exception\InvalidArgumentException
*/
public static function url($field, $value): bool
{
if ($field->isEmpty($value) === false) {
if (V::url($value) === false) {
throw new InvalidArgumentException(
V::message('url', $value)
);
}
}
return true;
}
return true;
}
}