src/parsers.php
<?php
namespace Gendiff\parsers;
use Symfony\Component\Yaml\Yaml;
function parse($data, $dataType)
{
switch ($dataType) {
case 'json':
return json_decode($data);
case 'yml':
case 'yaml':
return Yaml::parse($data, Yaml::PARSE_OBJECT_FOR_MAP);
default:
throw new \Exception("Invalid input format {$dataType}");
}
}