Update Kirby and Composer dependencies

This commit is contained in:
Paul Nicoué 2022-03-22 15:39:39 +01:00
parent f5d3ea5e84
commit ec74d78ba9
382 changed files with 25077 additions and 4955 deletions

View file

@ -2,6 +2,7 @@
use Kirby\Exception\Exception;
use Kirby\Form\Field;
use Kirby\Toolkit\Date;
use Kirby\Toolkit\I18n;
use Kirby\Toolkit\Str;
@ -20,12 +21,11 @@ return [
return $calendar;
},
/**
* Default date when a new page/file/user gets created
*/
'default' => function (string $default = null) {
return $default;
'default' => function (string $default = null): string {
return $this->toDatetime($default) ?? '';
},
/**
@ -46,42 +46,21 @@ return [
/**
* Latest date, which can be selected/saved (Y-m-d)
*/
'max' => function (string $max = null) {
return $this->toDatetime($max);
'max' => function (string $max = null): ?string {
return Date::optional($max);
},
/**
* Earliest date, which can be selected/saved (Y-m-d)
*/
'min' => function (string $min = null) {
return $this->toDatetime($min);
'min' => function (string $min = null): ?string {
return Date::optional($min);
},
/**
* Round to the nearest: sub-options for `unit` (day) and `size` (1)
*/
'step' => function ($step = null) {
$default = [
'size' => 1,
'unit' => 'day'
];
if ($step === null) {
return $default;
}
if (is_array($step) === true) {
$step = array_merge($default, $step);
$step['unit'] = strtolower($step['unit']);
return $step;
}
if (is_int($step) === true) {
return array_merge($default, ['size' => $step]);
}
if (is_string($step) === true) {
return array_merge($default, ['unit' => strtolower($step)]);
}
return $step;
},
/**
@ -95,12 +74,9 @@ return [
*/
'value' => function ($value = null) {
return $value;
},
}
],
'computed' => [
'default' => function () {
return $this->toDatetime($this->default);
},
'display' => function () {
if ($this->display) {
return Str::upper($this->display);
@ -120,57 +96,56 @@ return [
return $field->toArray();
},
'step' => function () {
if ($this->time === false) {
return $this->step;
if ($this->time === false || empty($this->time['step']) === true) {
return Date::stepConfig($this->step, [
'size' => 1,
'unit' => 'day'
]);
}
return $this->time['step'];
return Date::stepConfig($this->time['step'], [
'size' => 5,
'unit' => 'minute'
]);
},
'value' => function () {
return $this->toDatetime($this->value);
'value' => function (): string {
return $this->toDatetime($this->value) ?? '';
},
],
'validations' => [
'date',
'minMax' => function ($value) {
$min = $this->min ? strtotime($this->min) : null;
$max = $this->max ? strtotime($this->max) : null;
$value = strtotime($this->value());
if (!$value = Date::optional($value)) {
return true;
}
$min = Date::optional($this->min);
$max = Date::optional($this->max);
$format = $this->time === false ? 'd.m.Y' : 'd.m.Y H:i';
$errors = [];
if ($value && $min && $value < $min) {
$errors['min'] = $min;
}
if ($value && $max && $value > $max) {
$errors['max'] = $max;
}
if (empty($errors) === false) {
if ($min && $max) {
throw new Exception([
'key' => 'validation.date.between',
'data' => [
'min' => date($format, $min),
'max' => date($format, $max)
]
]);
} elseif ($min) {
throw new Exception([
'key' => 'validation.date.after',
'data' => [
'date' => date($format, $min),
]
]);
} else {
throw new Exception([
'key' => 'validation.date.before',
'data' => [
'date' => date($format, $max),
]
]);
}
if ($min && $max && $value->isBetween($min, $max) === false) {
throw new Exception([
'key' => 'validation.date.between',
'data' => [
'min' => $min->format($format),
'max' => $min->format($format)
]
]);
} elseif ($min && $value->isMin($min) === false) {
throw new Exception([
'key' => 'validation.date.after',
'data' => [
'date' => $min->format($format),
]
]);
} elseif ($max && $value->isMax($max) === false) {
throw new Exception([
'key' => 'validation.date.before',
'data' => [
'date' => $max->format($format),
]
]);
}
return true;

View file

@ -11,7 +11,7 @@ return [
],
'computed' => [
'value' => function () {
return trim($this->value);
return trim($this->value ?? '');
}
]
];

View file

@ -1,5 +1,7 @@
<?php
use Kirby\Toolkit\Date;
return [
'props' => [
/**
@ -11,16 +13,21 @@ return [
],
'methods' => [
'toDatetime' => function ($value, string $format = 'Y-m-d H:i:s') {
if ($timestamp = timestamp($value, $this->step)) {
return date($format, $timestamp);
if ($date = Date::optional($value)) {
if ($this->step) {
$step = Date::stepConfig($this->step);
$date->round($step['unit'], $step['size']);
}
return $date->format($format);
}
return null;
}
],
'save' => function ($value) {
if ($value !== null && $timestamp = strtotime($value)) {
return date($this->format, $timestamp);
if ($date = Date::optional($value)) {
return $date->format($this->format);
}
return '';

View file

@ -27,7 +27,7 @@ return [
* Sets the default text when a new page/file/user is created
*/
'default' => function (string $default = null) {
return trim($default);
return trim($default ?? '');
},
/**
@ -81,7 +81,7 @@ return [
},
'value' => function (string $value = null) {
return trim($value);
return trim($value ?? '');
}
],
'api' => function () {

View file

@ -1,6 +1,7 @@
<?php
use Kirby\Exception\Exception;
use Kirby\Toolkit\Date;
use Kirby\Toolkit\I18n;
return [
@ -11,11 +12,10 @@ return [
*/
'placeholder' => null,
/**
* Sets the default time when a new page/file/user is created
*/
'default' => function ($default = null) {
'default' => function ($default = null): ?string {
return $default;
},
@ -36,14 +36,14 @@ return [
/**
* Latest time, which can be selected/saved (H:i or H:i:s)
*/
'max' => function (string $max = null) {
return $max ? $this->toDatetime(date('Y-m-d ') . $max) : null;
'max' => function (string $max = null): ?string {
return Date::optional($max);
},
/**
* Earliest time, which can be selected/saved (H:i or H:i:s)
*/
'min' => function (string $min = null) {
return $min ? $this->toDatetime(date('Y-m-d ') . $min) : null;
'min' => function (string $min = null): ?string {
return Date::optional($min);
},
/**
@ -57,92 +57,67 @@ return [
* Round to the nearest: sub-options for `unit` (minute) and `size` (5)
*/
'step' => function ($step = null) {
$default = [
return Date::stepConfig($step, [
'size' => 5,
'unit' => 'minute'
];
if ($step === null) {
return $default;
}
if (is_array($step) === true) {
$step = array_merge($default, $step);
$step['unit'] = strtolower($step['unit']);
return $step;
}
if (is_int($step) === true) {
return array_merge($default, ['size' => $step]);
}
if (is_string($step) === true) {
return array_merge($default, ['unit' => strtolower($step)]);
}
'unit' => 'minute',
]);
},
'value' => function ($value = null) {
'value' => function ($value = null): ?string {
return $value;
}
],
'computed' => [
'default' => function () {
return $this->toDatetime($this->default, 'H:i:s');
},
'display' => function () {
if ($this->display) {
return $this->display;
}
return $this->notation === 24 ? 'HH:mm' : 'h:mm a';
return $this->notation === 24 ? 'HH:mm' : 'hh:mm a';
},
'default' => function (): string {
return $this->toDatetime($this->default, 'H:i:s') ?? '';
},
'format' => function () {
return $this->props['format'] ?? 'H:i:s';
},
'value' => function () {
return $this->toDatetime($this->value, 'H:i:s');
'value' => function (): ?string {
return $this->toDatetime($this->value, 'H:i:s') ?? '';
}
],
'validations' => [
'time',
'minMax' => function ($value) {
$min = $this->min ? strtotime($this->min) : null;
$max = $this->max ? strtotime($this->max) : null;
$value = strtotime($this->value());
if (!$value = Date::optional($value)) {
return true;
}
$min = Date::optional($this->min);
$max = Date::optional($this->max);
$format = 'H:i:s';
$errors = [];
if ($value && $min && $value < $min) {
$errors['min'] = $min;
}
if ($value && $max && $value > $max) {
$errors['max'] = $max;
}
if (empty($errors) === false) {
if ($min && $max) {
throw new Exception([
'key' => 'validation.time.between',
'data' => [
'min' => date($format, $min),
'max' => date($format, $max)
]
]);
} elseif ($min) {
throw new Exception([
'key' => 'validation.time.after',
'data' => [
'time' => date($format, $min),
]
]);
} else {
throw new Exception([
'key' => 'validation.time.before',
'data' => [
'time' => date($format, $max),
]
]);
}
if ($min && $max && $value->isBetween($min, $max) === false) {
throw new Exception([
'key' => 'validation.time.between',
'data' => [
'min' => $min->format($format),
'max' => $min->format($format)
]
]);
} elseif ($min && $value->isMin($min) === false) {
throw new Exception([
'key' => 'validation.time.after',
'data' => [
'time' => $min->format($format),
]
]);
} elseif ($max && $value->isMax($max) === false) {
throw new Exception([
'key' => 'validation.time.before',
'data' => [
'time' => $max->format($format),
]
]);
}
return true;

View file

@ -29,7 +29,8 @@ return [
],
'computed' => [
'value' => function () {
return Sane::sanitize(trim($this->value), 'html');
$value = trim($this->value ?? '');
return Sane::sanitize($value, 'html');
}
],
];