1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
<?php
namespace OneOfZero\Json\Mappers\File;
use RuntimeException;
use Symfony\Component\Yaml\Parser;
class YamlFileSource extends FileSource
{
public function __construct($file)
{
parent::__construct($file);
if (!class_exists(Parser::class))
{
throw new RuntimeException('The package symfony/yaml is required to be able to use the yaml mapper');
}
}
protected function load()
{
$parser = new Parser();
$this->mapping = $parser->parse(file_get_contents($this->getFile()));
$this->aliases = array_key_exists('@use', $this->mapping) ? $this->mapping['@use'] : [];
}
}