Cerys
3 weeks ago
10 changed files with 79 additions and 27 deletions
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Darksparrow\DeegraphInteractions\DataStructures; |
||||
|
|
||||
|
use DateTime; |
||||
|
|
||||
|
class DeegraphNodeDetails |
||||
|
{ |
||||
|
public string $ID; |
||||
|
public DateTime $CreatedAt; |
||||
|
public string $CreatorID; |
||||
|
|
||||
|
public array $OtherProperties; |
||||
|
|
||||
|
public function __construct(array $nodeDetails) |
||||
|
{ |
||||
|
$this->ID = $nodeDetails["@id"]; |
||||
|
$this->CreatedAt = new DateTime($nodeDetails["@created"]); |
||||
|
$this->CreatorID = $nodeDetails["@creator"]; |
||||
|
|
||||
|
foreach($nodeDetails as $key=>$value) { |
||||
|
switch($key) |
||||
|
{ |
||||
|
case "@id": |
||||
|
$this->ID = $value; |
||||
|
break; |
||||
|
case "@created": |
||||
|
$this->CreatedAt = new DateTime($value); |
||||
|
break; |
||||
|
case "@creator": |
||||
|
$this->CreatorID = $value; |
||||
|
break; |
||||
|
default: |
||||
|
$this->OtherProperties[$key] = $value; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public function AsJSON(): string |
||||
|
{ |
||||
|
$builder = [ |
||||
|
"@id" => $this->ID, |
||||
|
"@created" => $this->CreatedAt->format(format: 'Y-m-d\TH:i:s.v\Z'), |
||||
|
"@creator" => $this->CreatorID, |
||||
|
]; |
||||
|
foreach($this->OtherProperties as $key=>$value) { |
||||
|
$builder[$key] = $value; |
||||
|
} |
||||
|
return json_encode($builder); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue