mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
Add php-cs-fixer
This commit is contained in:
parent
e00e6ece5f
commit
309ae17036
54 changed files with 4900 additions and 4106 deletions
|
|
@ -11,30 +11,30 @@ use GuzzleHttp\Exception\GuzzleException;
|
|||
* Doesn't do any post-processing on the result
|
||||
*/
|
||||
class RawParser {
|
||||
/** @var string */
|
||||
private $parserUrl;
|
||||
/** @var string */
|
||||
private $parserUrl;
|
||||
|
||||
public function __construct(string $parserUrl) {
|
||||
$this->parserUrl = $parserUrl;
|
||||
}
|
||||
public function __construct(string $parserUrl) {
|
||||
$this->parserUrl = $parserUrl;
|
||||
}
|
||||
|
||||
public function parse(string $path): ?array {
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->post($this->parserUrl, [
|
||||
'body' => fopen($path, 'r')
|
||||
]);
|
||||
$result = json_decode($response->getBody()->getContents(), true);
|
||||
if (is_null($result)) {
|
||||
throw new \Exception('Failed to parse demo, unexpected result from parser');
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
} catch (GuzzleException $e) {
|
||||
if (strpos($e->getMessage(), 'cURL error 52') !== false) {
|
||||
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
|
||||
}
|
||||
throw new \Exception('Failed to parse demo, ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
public function parse(string $path): ?array {
|
||||
try {
|
||||
$client = new Client();
|
||||
$response = $client->post($this->parserUrl, [
|
||||
'body' => fopen($path, 'r')
|
||||
]);
|
||||
$result = json_decode($response->getBody()->getContents(), true);
|
||||
if (is_null($result)) {
|
||||
throw new \Exception('Failed to parse demo, unexpected result from parser');
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
} catch (GuzzleException $e) {
|
||||
if (strpos($e->getMessage(), 'cURL error 52') !== false) {
|
||||
throw new \Exception('Failed to parse demo, can\'t reach demo parser');
|
||||
}
|
||||
throw new \Exception('Failed to parse demo, ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue