Improved Peer Resolution and fixed minor bugs and issues, completed todo
This commit is contained in:
parent
7a39b0fd35
commit
8c2cbf48d5
5 changed files with 209 additions and 155 deletions
|
@ -7,6 +7,7 @@
|
|||
use Socialbox\Classes\Configuration;
|
||||
use Socialbox\Enums\Flags\PeerFlags;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\Standard\InformationFieldState;
|
||||
use Socialbox\Objects\Standard\Peer;
|
||||
|
||||
class PeerDatabaseRecord implements SerializableInterface
|
||||
|
@ -197,13 +198,14 @@
|
|||
/**
|
||||
* Converts the current instance to a Peer object.
|
||||
*
|
||||
* @param PeerInformationFieldRecord[]|InformationFieldState[]|array $informationFields
|
||||
* @return Peer The Peer representation of the current instance.
|
||||
*/
|
||||
public function toStandardPeer(): Peer
|
||||
public function toStandardPeer(array $informationFields): Peer
|
||||
{
|
||||
// TODO: TO be updated
|
||||
return Peer::fromArray([
|
||||
'address' => $this->getAddress(),
|
||||
'information_fields' => $informationFields,
|
||||
'flags' => array_map(fn(PeerFlags $flag) => $flag->value, $this->flags),
|
||||
'registered' => $this->created->getTimestamp()
|
||||
]);
|
||||
|
|
|
@ -1,159 +1,151 @@
|
|||
<?php
|
||||
|
||||
namespace Socialbox\Objects\Standard;
|
||||
namespace Socialbox\Objects\Standard;
|
||||
|
||||
use DateTime;
|
||||
use Socialbox\Enums\Flags\PeerFlags;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\Database\PeerRecord;
|
||||
use DateTime;
|
||||
use Socialbox\Enums\Flags\PeerFlags;
|
||||
use Socialbox\Interfaces\SerializableInterface;
|
||||
use Socialbox\Objects\Database\PeerDatabaseRecord;
|
||||
|
||||
class SelfUser implements SerializableInterface
|
||||
{
|
||||
private string $uuid;
|
||||
private bool $enabled;
|
||||
private string $address;
|
||||
private string $username;
|
||||
private ?string $displayName;
|
||||
/**
|
||||
* @var PeerFlags[]
|
||||
*/
|
||||
private array $flags;
|
||||
private int $created;
|
||||
|
||||
/**
|
||||
* Constructor for initializing the object with provided data.
|
||||
*
|
||||
* @param array|PeerRecord $data Data array containing initial values for object properties.
|
||||
*/
|
||||
public function __construct(array|PeerRecord $data)
|
||||
class SelfUser implements SerializableInterface
|
||||
{
|
||||
if($data instanceof PeerRecord)
|
||||
private string $address;
|
||||
private string $username;
|
||||
/**
|
||||
* @var PeerFlags[]
|
||||
*/
|
||||
private array $flags;
|
||||
/**
|
||||
* @var InformationFieldState[]
|
||||
*/
|
||||
private array $informationFieldStates;
|
||||
private bool $passwordEnabled;
|
||||
private ?int $passwordLastUpdated;
|
||||
private bool $otpEnabled;
|
||||
private ?int $otpLastUpdated;
|
||||
private int $registered;
|
||||
|
||||
/**
|
||||
* Constructor for initializing the object with provided data.
|
||||
*
|
||||
* @param array $data Data array containing initial values for object properties.
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->uuid = $data->getUuid();
|
||||
$this->enabled = $data->isEnabled();
|
||||
$this->username = $data->getUsername();
|
||||
$this->address = $data->getAddress();
|
||||
$this->displayName = $data->getDisplayName();
|
||||
$this->flags = $data->getFlags();
|
||||
$this->created = $data->getCreated()->getTimestamp();
|
||||
$this->uuid = $data['uuid'];
|
||||
$this->enabled = $data['enabled'];
|
||||
$this->username = $data['username'];
|
||||
$this->address = $data['address'];
|
||||
$this->displayName = $data['display_name'] ?? null;
|
||||
|
||||
if(is_string($data['flags']))
|
||||
{
|
||||
$this->flags = PeerFlags::fromString($data['flags']);
|
||||
}
|
||||
elseif(is_array($data['flags']))
|
||||
{
|
||||
$this->flags = $data['flags'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->flags = [];
|
||||
}
|
||||
|
||||
if($data['created'] instanceof DateTime)
|
||||
{
|
||||
$this->registered = $data['created']->getTimestamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->registered = $data['created'];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->uuid = $data['uuid'];
|
||||
$this->enabled = $data['enabled'];
|
||||
$this->username = $data['username'];
|
||||
$this->address = $data['address'];
|
||||
$this->displayName = $data['display_name'] ?? null;
|
||||
|
||||
if(is_string($data['flags']))
|
||||
/**
|
||||
* Retrieves the UUID of the object.
|
||||
*
|
||||
* @return string The UUID of the object.
|
||||
*/
|
||||
public function getUuid(): string
|
||||
{
|
||||
$this->flags = PeerFlags::fromString($data['flags']);
|
||||
}
|
||||
elseif(is_array($data['flags']))
|
||||
{
|
||||
$this->flags = $data['flags'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->flags = [];
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
if($data['created'] instanceof DateTime)
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
$this->created = $data['created']->getTimestamp();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->created = $data['created'];
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the UUID of the object.
|
||||
*
|
||||
* @return string The UUID of the object.
|
||||
*/
|
||||
public function getUuid(): string
|
||||
{
|
||||
return $this->uuid;
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string The username of the user.
|
||||
*/
|
||||
public function getUsername(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getAddress(): string
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string|null The display name.
|
||||
*/
|
||||
public function getDisplayName(): ?string
|
||||
{
|
||||
return $this->displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFlags(): array
|
||||
{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int The timestamp when the object was created.
|
||||
*/
|
||||
public function getCreated(): int
|
||||
{
|
||||
return $this->created;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): SelfUser
|
||||
{
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$flags = [];
|
||||
foreach($this->flags as $flag)
|
||||
/**
|
||||
*
|
||||
* @return string The username of the user.
|
||||
*/
|
||||
public function getUsername(): string
|
||||
{
|
||||
$flags[] = $flag->value;
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'enabled' => $this->enabled,
|
||||
'username' => $this->username,
|
||||
'address' => $this->address,
|
||||
'display_name' => $this->displayName,
|
||||
'flags' => $flags,
|
||||
'created' => $this->created
|
||||
];
|
||||
}
|
||||
}
|
||||
public function getAddress(): string
|
||||
{
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string|null The display name.
|
||||
*/
|
||||
public function getDisplayName(): ?string
|
||||
{
|
||||
return $this->displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFlags(): array
|
||||
{
|
||||
return $this->flags;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int The timestamp when the object was created.
|
||||
*/
|
||||
public function getRegistered(): int
|
||||
{
|
||||
return $this->registered;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public static function fromArray(array $data): SelfUser
|
||||
{
|
||||
return new self($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$flags = [];
|
||||
foreach($this->flags as $flag)
|
||||
{
|
||||
$flags[] = $flag->value;
|
||||
}
|
||||
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'enabled' => $this->enabled,
|
||||
'username' => $this->username,
|
||||
'address' => $this->address,
|
||||
'display_name' => $this->displayName,
|
||||
'flags' => $flags,
|
||||
'created' => $this->registered
|
||||
];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue