1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-04 02:14:06 +02:00
This commit is contained in:
Robin Appelman 2019-04-12 14:00:20 +02:00
commit 73469d2aa1
29 changed files with 140 additions and 149 deletions

View file

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Demostf\API\Demo;
use Demostf\API\Controllers\TempController;
use Exception;
use GuzzleHttp\Exception\RequestException;
/**
@ -16,25 +16,27 @@ class RawParser {
/** @var string */
private $parserPath;
private $tempController;
public function __construct(string $parserPath, TempController $tempController) {
public function __construct(string $parserPath) {
$this->parserPath = $parserPath;
$this->tempController = $tempController;
}
/**
* @param string $path
* @return array|null
* @throws Exception
*/
public function parse(string $path): ?array {
try {
$command = $this->parserPath . ' ' . escapeshellarg($path);
$output = shell_exec($command);
$result = \GuzzleHttp\json_decode($output, true);
if (null === $result) {
throw new \Exception('Failed to parse demo, unexpected result from parser');
throw new Exception('Failed to parse demo, unexpected result from parser');
} else {
return $result;
}
} catch (RequestException $e) {
throw new \Exception('Failed to parse demo, ' . $e->getMessage() . ' ' . $url);
throw new Exception('Failed to parse demo, ' . $e->getMessage());
}
}
}