Added Peer object
This commit is contained in:
parent
e726ad42e8
commit
f329cd34c4
1 changed files with 176 additions and 0 deletions
176
src/FederationLib/Objects/Standard/Peer.php
Normal file
176
src/FederationLib/Objects/Standard/Peer.php
Normal file
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
|
||||
/** @noinspection PhpMissingFieldTypeInspection */
|
||||
|
||||
namespace FederationLib\Objects\Standard;
|
||||
|
||||
use FederationLib\Interfaces\SerializableObjectInterface;
|
||||
|
||||
class Peer implements SerializableObjectInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $federated_address;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $client_first_seen;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $client_last_seen;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $active_restriction;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $permission_role;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $discovered_timestamp;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $seen_timestamp;
|
||||
|
||||
/**
|
||||
* Peer constructor.
|
||||
*
|
||||
* @param \FederationLib\Objects\Peer|null $peer
|
||||
*/
|
||||
public function __construct(?\FederationLib\Objects\Peer $peer=null)
|
||||
{
|
||||
if($peer === null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue