2019-09-06 18:52:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Translations;
|
|
|
|
|
|
|
|
use Illuminate\Contracts\Cache\Repository;
|
|
|
|
use Symfony\Component\Yaml\Yaml as YamlParser;
|
|
|
|
|
2019-09-07 21:23:38 +08:00
|
|
|
class Yaml
|
2019-09-06 18:52:34 +08:00
|
|
|
{
|
|
|
|
/** @var Repository */
|
|
|
|
protected $cache;
|
|
|
|
|
2019-09-07 10:32:26 +08:00
|
|
|
public function __construct(Repository $cache)
|
2019-09-06 18:52:34 +08:00
|
|
|
{
|
|
|
|
$this->cache = $cache;
|
|
|
|
}
|
|
|
|
|
2019-09-07 23:20:16 +08:00
|
|
|
public function parse(string $path): array
|
2019-09-06 18:52:34 +08:00
|
|
|
{
|
|
|
|
$key = 'yaml-trans-'.md5($path).'-'.filemtime($path);
|
2019-09-07 11:00:35 +08:00
|
|
|
|
2019-09-06 18:52:34 +08:00
|
|
|
return $this->cache->rememberForever($key, function () use ($path) {
|
|
|
|
return YamlParser::parseFile($path);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|