streams/Code/Lib/Yaml.php

43 lines
706 B
PHP
Raw Normal View History

2022-01-07 09:40:01 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Lib;
2022-01-07 09:40:01 +00:00
use Symfony\Component\Yaml\Yaml as Syaml;
use Symfony\Component\Yaml\Exception\ParseException;
class Yaml
{
public static function decode($data)
{
2022-03-25 20:49:50 +00:00
$value = false;
2022-01-07 09:40:01 +00:00
try {
$value = Syaml::parse($data);
} catch (ParseException $exception) {
logger('Unable to parse the YAML string: ' . $exception->getMessage());
}
return $value;
}
2022-08-13 10:57:14 +00:00
/**
* @param $data
* @return string
*/
public static function encode($data): string
{
2022-01-07 09:40:01 +00:00
return Syaml::dump($data);
}
2022-08-13 10:57:14 +00:00
/**
* @param $data
* @return string
*/
public static function fromJSON($data): string
{
2022-01-07 09:40:01 +00:00
return Syaml::dump(json_decode($data,true));
}
}