mirror of
https://github.com/flextype/flextype.git
synced 2025-08-07 05:36:54 +02:00
feat(serializers): code styles and format updates
This commit is contained in:
@@ -14,6 +14,7 @@ use function arrays;
|
||||
use function cache;
|
||||
use function count;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function ltrim;
|
||||
use function preg_replace;
|
||||
use function preg_split;
|
||||
@@ -41,7 +42,7 @@ class Frontmatter
|
||||
$headerSerializer = 'yaml';
|
||||
}
|
||||
|
||||
if (! in_array($headerSerializer, $allowed)) {
|
||||
if (! in_array($headerSerializer, $allowed)) {
|
||||
$headerSerializer = 'yaml';
|
||||
}
|
||||
|
||||
@@ -74,7 +75,7 @@ class Frontmatter
|
||||
$headerSerializer = 'yaml';
|
||||
}
|
||||
|
||||
if (! in_array($headerSerializer, $allowed)) {
|
||||
if (! in_array($headerSerializer, $allowed)) {
|
||||
$headerSerializer = 'yaml';
|
||||
}
|
||||
|
||||
|
@@ -61,7 +61,7 @@ class Json
|
||||
* Takes a JSON encoded string and converts it into a PHP variable.
|
||||
*
|
||||
* @param string $input A string containing JSON
|
||||
*
|
||||
*
|
||||
* @return mixed The JSON converted to a PHP value
|
||||
*
|
||||
* @throws RuntimeException If the JSON is not valid
|
||||
|
@@ -14,6 +14,7 @@ use RuntimeException;
|
||||
use function cache;
|
||||
use function registry;
|
||||
use function strings;
|
||||
use function var_export;
|
||||
|
||||
class PhpArray
|
||||
{
|
||||
|
@@ -12,8 +12,13 @@ namespace Flextype\Serializers;
|
||||
use RuntimeException;
|
||||
|
||||
use function cache;
|
||||
use function error_get_last;
|
||||
use function error_reporting;
|
||||
use function registry;
|
||||
use function strings;
|
||||
use function var_export;
|
||||
|
||||
use const E_ALL;
|
||||
|
||||
class PhpCode
|
||||
{
|
||||
@@ -47,22 +52,21 @@ class PhpCode
|
||||
$cache = registry()->get('flextype.settings.serializers.phpcode.decode.cache');
|
||||
|
||||
$decode = static function (string $input) {
|
||||
|
||||
$currentErrorLevel = error_reporting();
|
||||
error_reporting(E_ALL);
|
||||
$return = null;
|
||||
$eval = @eval('$return=' . $input . ';');
|
||||
$error = error_get_last();
|
||||
$eval = @eval('$return=' . $input . ';');
|
||||
$error = error_get_last();
|
||||
error_reporting($currentErrorLevel);
|
||||
|
||||
if ($eval === false || $error) {
|
||||
$msg = 'Decoding PhpCode failed';
|
||||
|
||||
|
||||
if ($eval === false) {
|
||||
$lastError = error_get_last();
|
||||
$msg .= ': ' . $lastError['message'];
|
||||
$msg .= ': ' . $lastError['message'];
|
||||
}
|
||||
|
||||
|
||||
throw new RuntimeException($msg, 0, $error);
|
||||
}
|
||||
|
||||
|
@@ -10,12 +10,6 @@ declare(strict_types=1);
|
||||
namespace Flextype\Serializers;
|
||||
|
||||
use Atomastic\Macroable\Macroable;
|
||||
use Flextype\Serializers\Json;
|
||||
use Flextype\Serializers\Yaml;
|
||||
use Flextype\Serializers\Frontmatter;
|
||||
use Flextype\Serializers\Neon;
|
||||
use Flextype\Serializers\PhpArray;
|
||||
use Flextype\Serializers\PhpCode;
|
||||
|
||||
class Serializers
|
||||
{
|
||||
@@ -44,7 +38,7 @@ class Serializers
|
||||
{
|
||||
return new Frontmatter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a Neon instance.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user