Upgrade to 3.2.0

This commit is contained in:
Bastian Allgeier
2019-06-25 09:56:08 +02:00
parent 9e18cf635d
commit 9c89153d35
296 changed files with 14408 additions and 2504 deletions

View File

@@ -8,18 +8,19 @@ use Kirby\Toolkit\F;
/**
* The `Data` class provides readers and
* writers for data. The class comes with
* three handlers for `json`, `yaml` and
* `txt` encoded data, but can be extended
* and customized.
* four handlers for `json`, `php`, `txt`
* and `yaml` encoded data, but can be
* extended and customized.
*
* The read and write methods automatically
* detect, which data handler to use in order
* detect which data handler to use in order
* to correctly encode and decode passed data.
*
* @package Kirby
* @author Bastian Allgeier <bastian@getkirby.com>
* @link http://getkirby.com
* @copyright Bastian Allgeier
* @link https://getkirby.com
* @copyright Bastian Allgeier GmbH
* @license https://opensource.org/licenses/MIT
*/
class Data
{
@@ -50,31 +51,31 @@ class Data
/**
* Handler getter
*
* @param string $type
* @return Handler|null
* @param string $type
* @return Kirby\Data\Handler
*/
public static function handler(string $type)
{
// normalize the type
$type = strtolower($type);
$handler = static::$handlers[$type] ?? null;
$type = strtolower($type);
if ($handler === null && isset(static::$aliases[$type]) === true) {
$handler = static::$handlers[static::$aliases[$type]] ?? null;
// find a handler or alias
$handler = static::$handlers[$type] ??
static::$handlers[static::$aliases[$type] ?? null] ??
null;
if (class_exists($handler)) {
return new $handler;
}
if ($handler === null) {
throw new Exception('Missing Handler for type: "' . $type . '"');
}
return new $handler;
throw new Exception('Missing handler for type: "' . $type . '"');
}
/**
* Decode data with the specified handler
* Decodes data with the specified handler
*
* @param string $data
* @param string $type
* @param string $data
* @param string $type
* @return array
*/
public static function decode(string $data = null, string $type): array
@@ -83,10 +84,10 @@ class Data
}
/**
* Encode data with the specified handler
* Encodes data with the specified handler
*
* @param array $data
* @param string $type
* @param array $data
* @param string $type
* @return string
*/
public static function encode(array $data = null, string $type): string
@@ -95,9 +96,9 @@ class Data
}
/**
* Reads data from a file
* The data handler is automatically chosen by
* the extension if not specified.
* Reads data from a file;
* the data handler is automatically chosen by
* the extension if not specified
*
* @param string $file
* @param string $type
@@ -109,13 +110,13 @@ class Data
}
/**
* Writes data to a file.
* The data handler is automatically chosen by
* the extension if not specified.
* Writes data to a file;
* the data handler is automatically chosen by
* the extension if not specified
*
* @param string $file
* @param array $data
* @param string $type
* @param string $file
* @param array $data
* @param string $type
* @return boolean
*/
public static function write(string $file = null, array $data = [], string $type = null): bool