Added Entity.php & EntityType.php

This commit is contained in:
netkas 2024-08-31 16:50:32 -04:00
parent c33becd392
commit ef62893f21
2 changed files with 98 additions and 0 deletions

View file

@ -0,0 +1,88 @@
<?php
namespace Socialbox\Abstracts;
use Socialbox\Enums\EntityType;
abstract class Entity
{
protected string $uuid;
protected EntityType $type;
protected string $username;
protected string $domain;
protected string $display_name;
/**
* Constructs the entity object from an array of data.
*
* @param array $data The data to construct the entity from.
*/
public function __construct(array $data)
{
$this->uuid = $data['uuid'];
$this->type = $data['type'];
$this->username = $data['username'];
$this->domain = $data['domain'];
$this->display_name = $data['display_name'];
}
/**
* Returns the Unique Universal Identifier (UUID v4) of the entity.
*
* @return string
*/
public function getUuid(): string
{
return $this->uuid;
}
/**
* Returns the EntityType of the entity.
*
* @return EntityType
*/
public function getType(): EntityType
{
return $this->type;
}
/**
* Returns the username of the entity.
*
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* Returns the domain that the entity belongs to, `LOCAL` for local entities.
*
* @return string
*/
public function getDomain(): string
{
return $this->domain;
}
/**
* Returns the display name of the entity.
*
* @return string
*/
public function getDisplayName(): string
{
return $this->display_name;
}
/**
* Returns the address of the entity in the format `username@domain`.
*
* @return string
*/
public function getAddress(): string
{
return sprintf('%s@%s', $this->username, $this->domain);
}
}

View file

@ -0,0 +1,10 @@
<?php
namespace Socialbox\Enums;
enum EntityType
{
case USER;
case BOARD;
case BOT;
}