From 93455104739c430ac0d71c3fc8b9e5f89d7c2a36 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 24 Apr 2019 22:32:02 +0300 Subject: [PATCH] Using clean JSON instead of YAML #123 #117 - YAML removed --- composer.json | 1 - flextype/parsers/YamlParser.php | 116 -------------------------------- 2 files changed, 117 deletions(-) delete mode 100644 flextype/parsers/YamlParser.php diff --git a/composer.json b/composer.json index 0869d8db..a227e9b5 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "require": { "php": ">=7.1.3", "doctrine/cache": "1.8.0", - "symfony/yaml": "4.2.5", "thunderer/shortcode": "0.7.1", "flextype-components/arr" : "1.2.5", "flextype-components/assets" : "1.0.3", diff --git a/flextype/parsers/YamlParser.php b/flextype/parsers/YamlParser.php deleted file mode 100644 index c49dd1b7..00000000 --- a/flextype/parsers/YamlParser.php +++ /dev/null @@ -1,116 +0,0 @@ - - * @link http://romanenko.digital - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Flextype; - -use Symfony\Component\Yaml\Yaml; -use Symfony\Component\Yaml\Exception\DumpException; -use Symfony\Component\Yaml\Exception\ParseException; - -class YamlParser { - - /** - * Inline - * - * The level where you switch to inline YAML - * - * @var int - */ - public static $inline = 5; - - /** - * Ident - * - * The amount of spaces to use for indentation of nested nodes - * - * @var int - */ - public static $indent = 2; - - /** - * Native - * - * Use native parser or symfony - * - * @var bool - */ - public static $native = true; - - /** - * Flag - * - * A bit field of PARSE_* constants to customize the YAML parser behavior - * - * @var int - */ - public static $flag = Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK|Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE; - - /** - * Dumps a PHP value to a YAML string. - * - * The dump method, when supplied with an array, will do its best - * to convert the array into friendly YAML. - * - * @param mixed $input The PHP value - * @param int $inline The level where you switch to inline YAML - * @param int $indent The amount of spaces to use for indentation of nested nodes - * @param int $flags A bit field of DUMP_* constants to customize the dumped YAML string - * - * @return string A YAML string representing the original PHP value - */ - public static function encode($input, int $inline = 5, int $indent = 2, int $flags = Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK|Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE) : string - { - try { - return Yaml::dump( - $input, - $inline ? $inline : YamlParser::$inline, - $indent ? $indent : YamlParser::$indent, - $flags ? $flags : YamlParser::$flag - ); - } catch (DumpException $e) { - throw new \RuntimeException('Encoding YAML failed: ' . $e->getMessage(), 0, $e); - } - } - - /** - * Parses YAML into a PHP value. - * - * $array = YamlParser::decode($yaml_file_content); - * - * @param string $input A string containing YAML - * @return mixed The YAML converted to a PHP value - * - * @throws ParseException If the YAML is not valid - */ - public static function decode(string $input) - { - // Try native PECL YAML PHP extension first if available. - if (YamlParser::$native && function_exists('yaml_parse')) { - - // Safely decode YAML. - $saved = @ini_get('yaml.decode_php'); - @ini_set('yaml.decode_php', 0); - $decoded = @yaml_parse($input); - @ini_set('yaml.decode_php', $saved); - - if ($decoded !== false) { - return (array) $decoded; - } - } - - try { - return (array) Yaml::parse($input); - } catch (ParseException $e) { - throw new \RuntimeException('Decoding YAML failed: ' . $e->getMessage(), 0, $e); - } - } -}