Upgrade to 3.9.3
This commit is contained in:
@@ -202,6 +202,18 @@ class BlocksField extends FieldClass
|
||||
return $this->valueToJson($blocks, $this->pretty());
|
||||
}
|
||||
|
||||
protected function setDefault($default = null)
|
||||
{
|
||||
// set id for blocks if not exists
|
||||
if (is_array($default) === true) {
|
||||
array_walk($default, function (&$block) {
|
||||
$block['id'] ??= Str::uuid();
|
||||
});
|
||||
}
|
||||
|
||||
parent::setDefault($default);
|
||||
}
|
||||
|
||||
protected function setFieldsets($fieldsets, $model)
|
||||
{
|
||||
if (is_string($fieldsets) === true) {
|
||||
|
@@ -115,6 +115,32 @@ class LayoutField extends BlocksField
|
||||
return $routes;
|
||||
}
|
||||
|
||||
protected function setDefault($default = null)
|
||||
{
|
||||
// set id for layouts, columns and blocks within layout if not exists
|
||||
if (is_array($default) === true) {
|
||||
array_walk($default, function (&$layout) {
|
||||
$layout['id'] ??= Str::uuid();
|
||||
|
||||
// set columns id within layout
|
||||
if (isset($layout['columns']) === true) {
|
||||
array_walk($layout['columns'], function (&$column) {
|
||||
$column['id'] ??= Str::uuid();
|
||||
|
||||
// set blocks id within column
|
||||
if (isset($column['blocks']) === true) {
|
||||
array_walk($column['blocks'], function (&$block) {
|
||||
$block['id'] ??= Str::uuid();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
parent::setDefault($default);
|
||||
}
|
||||
|
||||
protected function setLayouts(array $layouts = [])
|
||||
{
|
||||
$this->layouts = array_map(
|
||||
|
@@ -838,11 +838,13 @@ abstract class FieldClass
|
||||
*/
|
||||
protected function valueToJson(array $value = null, bool $pretty = false): string
|
||||
{
|
||||
$constants = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
|
||||
|
||||
if ($pretty === true) {
|
||||
return json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
$constants |= JSON_PRETTY_PRINT;
|
||||
}
|
||||
|
||||
return json_encode($value);
|
||||
return json_encode($value, $constants);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -66,7 +66,7 @@ class Params extends Obj
|
||||
$paramValue = $paramParts[1] ?? null;
|
||||
|
||||
if ($paramKey !== null) {
|
||||
$params[rawurldecode($paramKey)] = $paramValue ? rawurldecode($paramValue) : null;
|
||||
$params[rawurldecode($paramKey)] = $paramValue !== null ? rawurldecode($paramValue) : null;
|
||||
}
|
||||
|
||||
unset($path[$index]);
|
||||
|
@@ -33,7 +33,7 @@ class GdLib extends Darkroom
|
||||
$image = $this->blur($image, $options);
|
||||
$image = $this->grayscale($image, $options);
|
||||
|
||||
$image->toFile($file, $mime, $options['quality']);
|
||||
$image->toFile($file, $mime, $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
@@ -60,7 +60,11 @@ class GdLib extends Darkroom
|
||||
return $image->resize($options['width'], $options['height']);
|
||||
}
|
||||
|
||||
return $image->thumbnail($options['width'], $options['height'] ?? $options['width'], $options['crop']);
|
||||
return $image->thumbnail(
|
||||
$options['width'],
|
||||
$options['height'] ?? $options['width'],
|
||||
$options['crop']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -48,6 +48,17 @@ class A
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts the number of elements in an array
|
||||
*
|
||||
* @param array $array
|
||||
* @return int
|
||||
*/
|
||||
public static function count(array $array): int
|
||||
{
|
||||
return count($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an element of an array by key
|
||||
*
|
||||
@@ -150,6 +161,19 @@ class A
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if array has a value
|
||||
*
|
||||
* @param array $array
|
||||
* @param mixed $value
|
||||
* @param bool $strict
|
||||
* @return bool
|
||||
*/
|
||||
public static function has(array $array, $value, bool $strict = false): bool
|
||||
{
|
||||
return in_array($value, $array, $strict);
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins the elements of an array to a string
|
||||
*/
|
||||
@@ -309,6 +333,19 @@ class A
|
||||
return $prepend + $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce an array to a single value
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable $callback
|
||||
* @param mixed $initial
|
||||
* @return mixed
|
||||
*/
|
||||
public static function reduce(array $array, callable $callback, $initial = null): mixed
|
||||
{
|
||||
return array_reduce($array, $callback, $initial);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffles an array and keeps the keys
|
||||
*
|
||||
@@ -345,6 +382,36 @@ class A
|
||||
return $new;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a slice of an array
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $offset
|
||||
* @param int|null $length
|
||||
* @param bool $preserveKeys
|
||||
* @return array
|
||||
*/
|
||||
public static function slice(
|
||||
array $array,
|
||||
int $offset,
|
||||
int $length = null,
|
||||
bool $preserveKeys = false
|
||||
): array {
|
||||
return array_slice($array, $offset, $length, $preserveKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sums an array
|
||||
*
|
||||
* @param array $array
|
||||
* @return int|float
|
||||
*/
|
||||
public static function sum(array $array): int|float
|
||||
{
|
||||
return array_sum($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first element of an array
|
||||
*
|
||||
|
@@ -522,6 +522,49 @@ class Str
|
||||
return preg_replace('!^(' . preg_quote($trim) . ')+!', '', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Match string against a regular expression and return matches
|
||||
*
|
||||
* @param string $string The string to match
|
||||
* @param string $pattern The regular expression
|
||||
* @param int $flags Optional flags for PHP `preg_match()`
|
||||
* @param int $offset Positional offset in the string to start the search
|
||||
* @return array|null The matches or null if no match was found
|
||||
*/
|
||||
public static function match(string $string, string $pattern, int $flags = 0, int $offset = 0): ?array
|
||||
{
|
||||
$result = preg_match($pattern, $string, $matches, $flags, $offset);
|
||||
return ($result === 1) ? $matches : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a string matches a regular expression
|
||||
*
|
||||
* @param string $string The string to match
|
||||
* @param string $pattern The regular expression
|
||||
* @param int $flags Optional flags for PHP `preg_match()`
|
||||
* @param int $offset Positional offset in the string to start the search
|
||||
* @return bool True if the string matches the pattern
|
||||
*/
|
||||
public static function matches(string $string, string $pattern, int $flags = 0, int $offset = 0): bool
|
||||
{
|
||||
return static::match($string, $pattern, $flags, $offset) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Match string against a regular expression and return all matches
|
||||
*
|
||||
* @param string $string The string to match
|
||||
* @param string $pattern The regular expression
|
||||
* @param int $flags Optional flags for PHP `preg_match_all()`
|
||||
* @param int $offset Positional offset in the string to start the search
|
||||
* @return array|null The matches or null if no match was found
|
||||
*/
|
||||
public static function matchAll(string $string, string $pattern, int $flags = 0, int $offset = 0): ?array
|
||||
{
|
||||
$result = preg_match_all($pattern, $string, $matches, $flags, $offset);
|
||||
return ($result > 0) ? $matches : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a character pool with various possible combinations
|
||||
|
Reference in New Issue
Block a user