You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
<?php
|
|
|
|
namespace Darksparrow\DeegraphInteractions\DataStructures;
|
|
|
|
class QueryResponseWrapper
|
|
{
|
|
public array $Nodes;
|
|
|
|
public array $Rows;
|
|
public string $RowFormat;
|
|
|
|
public string $RuleID;
|
|
|
|
public static function FromAPIResponse(string $response): QueryResponseWrapper
|
|
{
|
|
$response = json_decode($response, true);
|
|
|
|
echo "\n\n\n";
|
|
var_dump($response);
|
|
echo "\n\n\n";
|
|
|
|
|
|
$builder = new QueryResponseWrapper();
|
|
|
|
if(array_key_exists(key: "@rows", array: $response))
|
|
{
|
|
$builder->Rows = [];
|
|
foreach($response["@rows"] as $row)
|
|
$builder->Rows[] = QueryResponseRow::FromArray(array: $row);
|
|
$builder->RowFormat = $response["@row_format"];
|
|
}
|
|
if(array_key_exists(key: "@nodes", array: $response))
|
|
{
|
|
$builder->Nodes = [];
|
|
foreach($response["@nodes"] as $row)
|
|
$builder->Nodes = $row;
|
|
}
|
|
if(array_key_exists(key: "@rule_id", array: $response))
|
|
{
|
|
$builder->RuleID = $response["@rule_id"];
|
|
}
|
|
|
|
return $builder;
|
|
}
|
|
|
|
public function FlattenRows(): array
|
|
{
|
|
$builder = [];
|
|
|
|
foreach($this->Rows as $row)
|
|
{
|
|
foreach($row->Results as $result)
|
|
{
|
|
$builder[] = $result;
|
|
}
|
|
}
|
|
|
|
return $builder;
|
|
}
|
|
}
|
|
|