From f329cd34c464807c18f2d1c7419e847492150317 Mon Sep 17 00:00:00 2001 From: Netkas Date: Mon, 19 Jun 2023 17:48:50 -0400 Subject: [PATCH] Added Peer object --- src/FederationLib/Objects/Standard/Peer.php | 176 ++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 src/FederationLib/Objects/Standard/Peer.php diff --git a/src/FederationLib/Objects/Standard/Peer.php b/src/FederationLib/Objects/Standard/Peer.php new file mode 100644 index 0000000..5c86283 --- /dev/null +++ b/src/FederationLib/Objects/Standard/Peer.php @@ -0,0 +1,176 @@ +federated_address = $peer->getFederatedAddress(); + $this->client_first_seen = $peer->getClientFirstSeen(); + $this->client_last_seen = $peer->getClientLastSeen(); + $this->active_restriction = $peer->getActiveRestriction(); + $this->permission_role = $peer->getPermissionRole(); + $this->discovered_timestamp = $peer->getDiscoveredTimestamp(); + $this->seen_timestamp = $peer->getSeenTimestamp(); + } + + /** + * Returns the federated address of the peer + * + * @return string + */ + public function getFederatedAddress(): string + { + return $this->federated_address; + } + + /** + * Returns the Client UUID that first saw the peer + * + * @return string + */ + public function getClientFirstSeen(): string + { + return $this->client_first_seen; + } + + /** + * Returns the Client UUID that last saw the peer + * + * @return string + */ + public function getClientLastSeen(): string + { + return $this->client_last_seen; + } + + /** + * Optional. Returns the ID of the active restriction applied to the peer + * if null, no restriction is applied + * + * @return string|null + */ + public function getActiveRestriction(): ?string + { + return $this->active_restriction; + } + + /** + * Returns the permission role of the peer + * + * @return int + */ + public function getPermissionRole(): int + { + return $this->permission_role; + } + + /** + * Returns the timestamp of when the peer was discovered by the client + * + * @return int + */ + public function getDiscoveredTimestamp(): int + { + return $this->discovered_timestamp; + } + + /** + * Returns the timestamp of when the peer was last seen by the client + * + * @return int + */ + public function getSeenTimestamp(): int + { + return $this->seen_timestamp; + } + + /** + * Returns an array representation of the object + * + * @return array + */ + public function toArray(): array + { + return [ + 'federated_address' => $this->federated_address, + 'client_first_seen' => $this->client_first_seen, + 'client_last_seen' => $this->client_last_seen, + 'active_restriction' => $this->active_restriction, + 'permission_role' => $this->permission_role, + 'discovered_timestamp' => $this->discovered_timestamp, + 'seen_timestamp' => $this->seen_timestamp + ]; + } + + /** + * Constructs object from an array representation + * + * @param array $array + * @return Peer + */ + public static function fromArray(array $array): Peer + { + $object = new self(); + + $object->federated_address = $array['federated_address']; + $object->client_first_seen = $array['client_first_seen']; + $object->client_last_seen = $array['client_last_seen']; + $object->active_restriction = $array['active_restriction']; + $object->permission_role = $array['permission_role']; + $object->discovered_timestamp = $array['discovered_timestamp']; + $object->seen_timestamp = $array['seen_timestamp']; + + return $object; + } + } \ No newline at end of file