Update to Kirby 4.7.0
This commit is contained in:
parent
02a9ab387c
commit
ba25a9a198
509 changed files with 26604 additions and 14872 deletions
|
@ -38,11 +38,11 @@ class Data
|
|||
* All registered handlers
|
||||
*/
|
||||
public static array $handlers = [
|
||||
'json' => 'Kirby\Data\Json',
|
||||
'php' => 'Kirby\Data\PHP',
|
||||
'txt' => 'Kirby\Data\Txt',
|
||||
'xml' => 'Kirby\Data\Xml',
|
||||
'yaml' => 'Kirby\Data\Yaml',
|
||||
'json' => Json::class,
|
||||
'php' => PHP::class,
|
||||
'txt' => Txt::class,
|
||||
'xml' => Xml::class,
|
||||
'yaml' => Yaml::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -54,10 +54,11 @@ class Data
|
|||
$type = strtolower($type);
|
||||
|
||||
// find a handler or alias
|
||||
$alias = static::$aliases[$type] ?? null;
|
||||
$handler =
|
||||
static::$handlers[$type] ??
|
||||
($alias ? static::$handlers[$alias] ?? null : null);
|
||||
$handler = static::$handlers[$type] ?? null;
|
||||
|
||||
if ($alias = static::$aliases[$type] ?? null) {
|
||||
$handler ??= static::$handlers[$alias] ?? null;
|
||||
}
|
||||
|
||||
if ($handler === null || class_exists($handler) === false) {
|
||||
throw new Exception('Missing handler for type: "' . $type . '"');
|
||||
|
@ -95,7 +96,9 @@ class Data
|
|||
*/
|
||||
public static function read(string $file, string|null $type = null): array
|
||||
{
|
||||
return static::handler($type ?? F::extension($file))->read($file);
|
||||
$type ??= F::extension($file);
|
||||
$handler = static::handler($type);
|
||||
return $handler->read($file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -108,6 +111,8 @@ class Data
|
|||
$data = [],
|
||||
string|null $type = null
|
||||
): bool {
|
||||
return static::handler($type ?? F::extension($file))->write($file, $data);
|
||||
$type ??= F::extension($file);
|
||||
$handler = static::handler($type);
|
||||
return $handler->write($file, $data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ class Txt extends Handler
|
|||
// avoid problems with arrays
|
||||
if (is_array($value) === true) {
|
||||
$value = Data::encode($value, 'yaml');
|
||||
// avoid problems with localized floats
|
||||
// avoid problems with localized floats
|
||||
} elseif (is_float($value) === true) {
|
||||
$value = Str::float($value);
|
||||
}
|
||||
|
@ -65,11 +65,10 @@ class Txt extends Handler
|
|||
$result = $key . ':';
|
||||
|
||||
// multi-line content
|
||||
if (preg_match('!\R!', $value) === 1) {
|
||||
$result .= "\n\n";
|
||||
} else {
|
||||
$result .= ' ';
|
||||
}
|
||||
$result .= match (preg_match('!\R!', $value)) {
|
||||
1 => "\n\n",
|
||||
default => ' ',
|
||||
};
|
||||
|
||||
$result .= $value;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue