philips-cnc6600-interpreter/src/Tool/Parser/ToolParser.php

40 lines
703 B
PHP

<?php
namespace Tool\Parser;
use InvalidArgumentException;
use Symfony\Component\Yaml\Yaml;
use Tool\Tool;
class ToolParser
{
/**
* @param string $yamlFile
* @return Tool[]
*/
public function parseFile(string $yamlFile): array
{
$data = @Yaml::parseFile($yamlFile);
if (is_null($data)) {
throw new InvalidArgumentException('Yaml file not found: ' . $yamlFile);
}
return $this->parse($data);
}
/**
* @param array $data
* @return Tool[]
*/
public function parse(array $data): array
{
$tools = [];
foreach ($data as $T => $tool) {
$T = (int)filter_var($T, FILTER_SANITIZE_NUMBER_INT);
$tools[] = new Tool($T, $tool['X'], $tool['Z']);
}
return $tools;
}
}