Cerys
3 weeks ago
4 changed files with 30 additions and 69 deletions
@ -1,30 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace Darksparrow\DeegraphInteractions\DataStructures; |
|
||||
|
|
||||
class QueryResponseRow |
|
||||
{ |
|
||||
public ?string $Search; |
|
||||
public ?array $Results; |
|
||||
|
|
||||
public function __construct(array $array) |
|
||||
{ |
|
||||
if($array == []) |
|
||||
{ |
|
||||
$this->Search = null; |
|
||||
$this->Results = null; |
|
||||
return; |
|
||||
} |
|
||||
$this->Search = key(array: $array); |
|
||||
foreach($array["{$this->Search}"] as $key=>$value) |
|
||||
{ |
|
||||
$this->Results[] = new KeyValuePair(key: $key, value: $value); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public function __toString(): string |
|
||||
{ |
|
||||
return json_encode($this, JSON_PRETTY_PRINT); |
|
||||
} |
|
||||
|
|
||||
} |
|
@ -1,36 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace Darksparrow\DeegraphInteractions\DataStructures; |
|
||||
|
|
||||
class QueryResponseWrapper |
|
||||
{ |
|
||||
public array $Rows; |
|
||||
public string $RowFormat; |
|
||||
|
|
||||
public static function FromAPIResponse(string $response): QueryResponseWrapper |
|
||||
{ |
|
||||
$temp = json_decode($response, true); |
|
||||
|
|
||||
$builder = new QueryResponseWrapper(); |
|
||||
|
|
||||
foreach($temp["@rows"] as $row) $builder->Rows[] = QueryResponseRow::FromArray(array: $row); |
|
||||
$builder->RowFormat = $temp["@row_format"]; |
|
||||
|
|
||||
return $builder; |
|
||||
} |
|
||||
|
|
||||
public function Flatten(): array |
|
||||
{ |
|
||||
$builder = []; |
|
||||
|
|
||||
foreach($this->Rows as $row) |
|
||||
{ |
|
||||
foreach($row->Results as $result) |
|
||||
{ |
|
||||
$builder[] = $result; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
return $builder; |
|
||||
} |
|
||||
} |
|
@ -0,0 +1,27 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery; |
||||
|
|
||||
|
class SelectQueryResponseRow |
||||
|
{ |
||||
|
public ?array $Properties = null; |
||||
|
|
||||
|
public function __construct(array $array) |
||||
|
{ |
||||
|
if($array == []) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
foreach($array as $property=>$data) |
||||
|
{ |
||||
|
foreach($data as $key => $value) { |
||||
|
$this->Properties[$property][$key] = $value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function __toString(): string |
||||
|
{ |
||||
|
return json_encode($this, JSON_PRETTY_PRINT); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue