switching to a faster YAML parser

This commit is contained in:
Joby Elliott 2021-09-08 10:37:13 -06:00
parent 6c44fb7103
commit 188dffe8d5
3 changed files with 8 additions and 7 deletions

View file

@ -27,6 +27,6 @@
},
"require": {
"php": ">=7.1",
"symfony/yaml": "^4|^3|^2"
"mustangostang/spyc": "^0.6.3"
}
}

View file

@ -1,9 +1,10 @@
<?php
/* Flatrr | https://gitlab.com/byjoby/flatrr | MIT License */
namespace Flatrr\Config;
use Flatrr\SelfReferencingFlatArray;
use Symfony\Component\Yaml\Yaml;
use Spyc;
class Config extends SelfReferencingFlatArray implements ConfigInterface
{
@ -40,7 +41,7 @@ class Config extends SelfReferencingFlatArray implements ConfigInterface
protected function parse_yaml($input)
{
return Yaml::parse($input);
return Spyc::YAMLLoadString($input);
}
public function json($raw = false): string
@ -50,7 +51,7 @@ class Config extends SelfReferencingFlatArray implements ConfigInterface
public function yaml($raw = false): string
{
return Yaml::dump($this->get(null, $raw), 10);
return Spyc::YAMLDump($this->get(null, $raw), 2);
}
protected function read_ini($filename)
@ -65,7 +66,7 @@ class Config extends SelfReferencingFlatArray implements ConfigInterface
protected function read_yaml($filename)
{
return Yaml::parse(file_get_contents($filename));
return Spyc::YAMLLoad($filename);
}
protected function read_yml($filename)

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Flatrr\Config;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;
use Spyc;
class ConfigTest extends TestCase
{
@ -50,6 +50,6 @@ class ConfigTest extends TestCase
//json
$this->assertEquals($data, json_decode($c->json(), true));
//yaml
$this->assertEquals($data, Yaml::parse($c->yaml()));
$this->assertEquals($data, Spyc::YAMLLoad($c->yaml()));
}
}