7 changed files with 99 additions and 11 deletions
			
			
		| @ -0,0 +1,32 @@ | |||||
|  | <?php | ||||
|  | 
 | ||||
|  | namespace Darksparrow\DeegraphInteractions\DataStructures; | ||||
|  | 
 | ||||
|  | class KeyValuePair | ||||
|  | { | ||||
|  |     public string $Key; | ||||
|  |     public ?string $Value; | ||||
|  | 
 | ||||
|  |     public function __construct(string $key, ?string $value) | ||||
|  |     { | ||||
|  |         $this->Key = $key; | ||||
|  |         $this->Value = $value; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     public function __toString(): string | ||||
|  |     { | ||||
|  |         if(isset($this->Key) && isset($this->Value)) | ||||
|  |             return "{$this->Key} => \"{$this->Value}\""; | ||||
|  | 
 | ||||
|  |         if(!isset($this->Key) && isset($this->Value)) | ||||
|  |             return "NULL => \"{$this->Value}\""; | ||||
|  | 
 | ||||
|  |         if(isset($this->Key) && !isset($this->Value)) | ||||
|  |             return "{$this->Key} => NULL"; | ||||
|  | 
 | ||||
|  |         if(isset($this->Key) && isset($this->Value)) | ||||
|  |             return "NULL => NULL"; | ||||
|  | 
 | ||||
|  |         return "FAIL"; | ||||
|  |     } | ||||
|  | } | ||||
| @ -0,0 +1,28 @@ | |||||
|  | <?php | ||||
|  | 
 | ||||
|  | namespace Darksparrow\DeegraphInteractions\DataStructures; | ||||
|  | 
 | ||||
|  | class QueryResponseRow | ||||
|  | { | ||||
|  |     public string $Search; | ||||
|  |     public array $Results; | ||||
|  | 
 | ||||
|  |     public static function FromArray(array $array): QueryResponseRow | ||||
|  |     { | ||||
|  |         $builder = new QueryResponseRow(); | ||||
|  | 
 | ||||
|  |         $builder->Search = key(array: $array); | ||||
|  |         foreach($array["{$builder->Search}"] as $key=>$value) | ||||
|  |         { | ||||
|  |             $builder->Results[] = new KeyValuePair(key: $key, value: $value); | ||||
|  |         } | ||||
|  | 
 | ||||
|  |         return $builder; | ||||
|  |     } | ||||
|  | 
 | ||||
|  |     public function __toString(): string | ||||
|  |     { | ||||
|  |         return json_encode($this, JSON_PRETTY_PRINT); | ||||
|  |     } | ||||
|  | 
 | ||||
|  | } | ||||
					Loading…
					
					
				
		Reference in new issue