Upgrade to 3.5.7

This commit is contained in:
Bastian Allgeier
2021-07-02 11:34:29 +02:00
parent 5358f8885c
commit 62b533a28f
37 changed files with 329 additions and 233 deletions

View File

@@ -221,6 +221,7 @@ class Dir
* @param string $dir The path for the new directory
* @param bool $recursive Create all parent directories, which don't exist
* @return bool True: the dir has been created, false: creating failed
* @throws \Exception If a file with the provided path already exists or the parent directory is not writable
*/
public static function make(string $dir, bool $recursive = true): bool
{
@@ -232,6 +233,10 @@ class Dir
return true;
}
if (is_file($dir) === true) {
throw new Exception(sprintf('A file with the name "%s" already exists', $dir));
}
$parent = dirname($dir);
if ($recursive === true) {

View File

@@ -250,7 +250,7 @@ class Str
*/
public static function contains(string $string = null, string $needle, bool $caseInsensitive = false): bool
{
return call_user_func($caseInsensitive === true ? 'stristr' : 'strstr', $string, $needle) !== false;
return call_user_func($caseInsensitive === true ? 'stripos' : 'strpos', $string, $needle) !== false;
}
/**
@@ -962,17 +962,32 @@ class Str
*
* </code>
*
* @param string $string The string with placeholders
* @param string|null $string The string with placeholders
* @param array $data Associative array with placeholders as
* keys and replacements as values
* @param string $fallback A fallback if a token does not have any matches
* @param string|array|null $fallback An options array that contains:
* - fallback: if a token does not have any matches
* - callback: to be able to handle each matching result
* - start: start placeholder
* - end: end placeholder
* A simple fallback string is supported for compatibility (but deprecated).
* @param string $start Placeholder start characters
* @param string $end Placeholder end characters
*
* @todo Deprecate `string $fallback` and `$start`/`$end` arguments with warning in 3.6.0
* @todo Remove `$start` and `$end` parameters, rename `$fallback` to `$options` and only support `array` type for `$options` in 3.7.0
*
* @return string The filled-in string
*/
public static function template(string $string = null, array $data = [], string $fallback = null, string $start = '{{', string $end = '}}'): string
public static function template(string $string = null, array $data = [], $fallback = null, string $start = '{{', string $end = '}}'): string
{
return preg_replace_callback('!' . $start . '(.*?)' . $end . '!', function ($match) use ($data, $fallback) {
$options = $fallback;
$fallback = is_string($options) === true ? $options : ($options['fallback'] ?? null);
$callback = is_a(($options['callback'] ?? null), 'Closure') === true ? $options['callback'] : null;
$start = (string)($options['start'] ?? $start);
$end = (string)($options['end'] ?? $end);
return preg_replace_callback('!' . $start . '(.*?)' . $end . '!', function ($match) use ($data, $fallback, $callback) {
$query = trim($match[1]);
// if the placeholder contains a dot, it is a query
@@ -991,6 +1006,11 @@ class Str
$result = $fallback;
}
// callback on result if given
if ($callback !== null) {
$result = $callback((string)$result, $query, $data);
}
// if we still don't have a result, keep the original placeholder
return $result ?? $match[0];
}, $string);

View File

@@ -463,6 +463,12 @@ V::$validators = [
* Checks that the value has the given size
*/
'size' => function ($value, $size, $operator = '=='): bool {
// if value is field object, first convert it to a readable value
// it is important to check at the beginning as the value can be string or numeric
if (is_a($value, '\Kirby\Cms\Field') === true) {
$value = $value->value();
}
if (is_numeric($value) === true) {
$count = $value;
} elseif (is_string($value) === true) {