mirror of
https://github.com/getgrav/grav.git
synced 2026-01-28 18:30:07 +01:00
Switch to Grav YAML wrapper that supports native and fallback YAML libs
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
* Added static `Grav\Common\Yaml` class which should be used instead of `Symfony\Component\Yaml\Yaml`
|
||||
1. [](#improved)
|
||||
* Updated deprecated Twig code so it works in both in Twig 1.34+ and Twig 2.4+
|
||||
* Switched to new Grav Yaml class to support Native + Fallback YAML libraries
|
||||
1. [](#bugfix)
|
||||
* Broken handling of user folder in Grav URI object [#2151](https://github.com/getgrav/grav/issues/2151)
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ namespace Grav\Common\Data;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Grav\Common\Yaml;
|
||||
use RocketTheme\Toolbox\Compat\Yaml\Yaml as FallbackYaml;
|
||||
|
||||
class Validation
|
||||
@@ -649,19 +648,8 @@ class Validation
|
||||
return $value;
|
||||
}
|
||||
|
||||
try {
|
||||
return (array) Yaml::parse($value);
|
||||
} catch (ParseException $e) {
|
||||
// If YAML compatibility mode is set on, fall back to older YAML parser.
|
||||
if (Grav::instance()['config']->get('system.strict_mode.yaml_compat', true)) {
|
||||
try {
|
||||
return (array) FallbackYaml::parse($value);
|
||||
} catch (ParseException $e2) {
|
||||
}
|
||||
}
|
||||
return (array) Yaml::parse($value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
namespace Grav\Common\Page;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Yaml;
|
||||
use Grav\Common\Page\Medium\AbstractMedia;
|
||||
use Grav\Common\Page\Medium\GlobalMedia;
|
||||
use Grav\Common\Page\Medium\MediumFactory;
|
||||
use RocketTheme\Toolbox\File\File;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class Media extends AbstractMedia
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ use Grav\Common\Data\Blueprint;
|
||||
use Grav\Common\File\CompiledYamlFile;
|
||||
use Grav\Common\Filesystem\Folder;
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Language\Language;
|
||||
use Grav\Common\Markdown\Parsedown;
|
||||
use Grav\Common\Markdown\ParsedownExtra;
|
||||
use Grav\Common\Page\Interfaces\PageInterface;
|
||||
@@ -23,10 +22,9 @@ use Grav\Common\Media\Traits\MediaTrait;
|
||||
use Grav\Common\Taxonomy;
|
||||
use Grav\Common\Uri;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Yaml;
|
||||
use RocketTheme\Toolbox\Event\Event;
|
||||
use RocketTheme\Toolbox\File\MarkdownFile;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
define('PAGE_ORDER_PREFIX_REGEX', '/^[0-9]+\./u');
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ use Grav\Common\Twig\TokenParser\TwigTokenParserTryCatch;
|
||||
use Grav\Common\Twig\TokenParser\TwigTokenParserMarkdown;
|
||||
use Grav\Common\User\User;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Common\Yaml;
|
||||
use Grav\Common\Markdown\Parsedown;
|
||||
use Grav\Common\Markdown\ParsedownExtra;
|
||||
use Grav\Common\Helpers\Base32;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
|
||||
{
|
||||
@@ -1297,11 +1297,12 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
* Dump/Encode data into YAML format
|
||||
*
|
||||
* @param $data
|
||||
* @param $inline integer number of levels of inline syntax
|
||||
* @return mixed
|
||||
*/
|
||||
public function yamlEncodeFilter($data)
|
||||
public function yamlEncodeFilter($data, $inline = 10)
|
||||
{
|
||||
return Yaml::dump($data, 10);
|
||||
return Yaml::dump($data, $inline);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,13 +24,13 @@ abstract class Yaml
|
||||
return static::$yaml->decode($data);
|
||||
}
|
||||
|
||||
public static function dump($data)
|
||||
public static function dump($data, $inline = null, $indent = null)
|
||||
{
|
||||
if (null === static::$yaml) {
|
||||
static::init();
|
||||
}
|
||||
|
||||
return static::$yaml->encode($data);
|
||||
return static::$yaml->encode($data, $inline, $indent);
|
||||
}
|
||||
|
||||
private static function init()
|
||||
|
||||
@@ -58,13 +58,13 @@ class YamlFormatter implements FormatterInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function encode($data)
|
||||
public function encode($data, $inline = null, $indent = null)
|
||||
{
|
||||
try {
|
||||
return (string) YamlParser::dump(
|
||||
$data,
|
||||
$this->config['inline'],
|
||||
$this->config['indent'],
|
||||
$inline ?: $this->config['inline'],
|
||||
$indent ?: $this->config['indent'],
|
||||
YamlParser::DUMP_EXCEPTION_ON_INVALID_TYPE
|
||||
);
|
||||
} catch (DumpException $e) {
|
||||
|
||||
Reference in New Issue
Block a user