switching to a faster YAML parser
This commit is contained in:
parent
6c44fb7103
commit
188dffe8d5
3 changed files with 8 additions and 7 deletions
|
@ -27,6 +27,6 @@
|
|||
},
|
||||
"require": {
|
||||
"php": ">=7.1",
|
||||
"symfony/yaml": "^4|^3|^2"
|
||||
"mustangostang/spyc": "^0.6.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue