Cerys Lewis
5 months ago
1 changed files with 0 additions and 60 deletions
@ -1,60 +0,0 @@ |
|||||
<?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; |
|
||||
} |
|
||||
} |
|
Loading…
Reference in new issue