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": { "require": {
"php": ">=7.1", "php": ">=7.1",
"symfony/yaml": "^4|^3|^2" "mustangostang/spyc": "^0.6.3"
} }
} }

View file

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

View file

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