federationlib/src/FederationLib/Objects/Standard/Client.php

192 lines
No EOL
4.6 KiB
PHP

<?php
/** @noinspection PhpMissingFieldTypeInspection */
namespace FederationLib\Objects\Standard;
use FederationLib\Interfaces\SerializableObjectInterface;
use FederationLib\Objects\ClientRecord;
class Client implements SerializableObjectInterface
{
/**
* @var string
*/
private $uuid;
/**
* @var bool
*/
private $enabled;
/**
* @var string
*/
private $name;
/**
* @var string|null
*/
private $description;
/**
* @var int
*/
private $permission_role;
/**
* @var int
*/
private $created_timestamp;
/**
* @var int
*/
private $updated_timestamp;
/**
* @var int
*/
private $seen_timestamp;
/**
* Client constructor.
*
* @param ClientRecord|null $client
*/
public function __construct(?ClientRecord $client=null)
{
if($client === null)
{
return;
}
$this->uuid = $client->getUuid();
$this->enabled = $client->isEnabled();
$this->name = $client->getName();
$this->description = $client->getDescription();
$this->permission_role = $client->getPermissionRole();
$this->created_timestamp = $client->getCreatedTimestamp();
$this->updated_timestamp = $client->getUpdatedTimestamp();
$this->seen_timestamp = $client->getSeenTimestamp();
}
/**
* Returns the Client's UUID
*
* @return string
*/
public function getUuid(): string
{
return $this->uuid;
}
/**
* Returns True if the Client is enabled, False otherwise
*
* @return bool
*/
public function isEnabled(): bool
{
return $this->enabled;
}
/**
* Returns the Client's name
*
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* Optional. Returns the Client's description
*
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* Returns the Client's permission role
*
* @return int
*/
public function getPermissionRole(): int
{
return $this->permission_role;
}
/**
* Returns the Client's creation timestamp
*
* @return int
*/
public function getCreatedTimestamp(): int
{
return $this->created_timestamp;
}
/**
* Returns the Client's last update timestamp
*
* @return int
*/
public function getUpdatedTimestamp(): int
{
return $this->updated_timestamp;
}
/**
* Returns the Client's last seen timestamp
*
* @return int
*/
public function getSeenTimestamp(): int
{
return $this->seen_timestamp;
}
/**
* Returns an array representation of the object
*
* @return array
*/
public function toArray(): array
{
return [
'uuid' => $this->uuid,
'enabled' => $this->enabled,
'name' => $this->name,
'description' => $this->description,
'created_timestamp' => $this->created_timestamp,
'updated_timestamp' => $this->updated_timestamp,
'seen_timestamp' => $this->seen_timestamp
];
}
/**
* Constructs an object from an array representation
*
* @param array $array
* @return Client
*/
public static function fromArray(array $array): Client
{
$object = new self();
$object->uuid = $array['uuid'];
$object->enabled = $array['enabled'];
$object->name = $array['name'];
$object->description = $array['description'];
$object->created_timestamp = $array['created_timestamp'];
$object->updated_timestamp = $array['updated_timestamp'];
$object->seen_timestamp = $array['seen_timestamp'];
return $object;
}
}