Browse Source

better handing for different responses

Cerys Lewis 5 months ago
parent
commit
841a433ded
  1. 26
      src/DataStructures/QueryResponseWrapper.php

26
src/DataStructures/QueryResponseWrapper.php

@ -4,22 +4,40 @@ namespace Darksparrow\DeegraphInteractions\DataStructures;
class QueryResponseWrapper class QueryResponseWrapper
{ {
public array $Nodes;
public array $Rows; public array $Rows;
public string $RowFormat; public string $RowFormat;
public static function FromAPIResponse(string $response): QueryResponseWrapper public static function FromAPIResponse(string $response): QueryResponseWrapper
{ {
$temp = json_decode($response, true); $response = json_decode($response, true);
echo "\n\n\n";
var_dump($response);
echo "\n\n\n";
$builder = new QueryResponseWrapper(); $builder = new QueryResponseWrapper();
foreach($temp["@rows"] as $row) $builder->Rows[] = QueryResponseRow::FromArray(array: $row); if(array_key_exists(key: "@rows", array: $response))
$builder->RowFormat = $temp["@row_format"]; {
$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 = $response["@nodes"];
}
return $builder; return $builder;
} }
public function Flatten(): array public function FlattenRows(): array
{ {
$builder = []; $builder = [];

Loading…
Cancel
Save