2024-10-30 15:12:55 -04:00
|
|
|
<?php
|
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
namespace Socialbox\Classes\Configuration;
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
class InstanceConfiguration
|
|
|
|
{
|
|
|
|
private bool $enabled;
|
|
|
|
private ?string $domain;
|
|
|
|
private ?string $rpcEndpoint;
|
2024-12-10 22:14:43 -05:00
|
|
|
private int $encryptionKeysCount;
|
|
|
|
private int $encryptionRecordsCount;
|
2024-12-10 13:30:08 -05:00
|
|
|
private ?string $privateKey;
|
|
|
|
private ?string $publicKey;
|
2024-12-10 22:14:43 -05:00
|
|
|
private ?array $encryptionKeys;
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
/**
|
|
|
|
* Constructor that initializes object properties with the provided data.
|
|
|
|
*
|
|
|
|
* @param array $data An associative array with keys 'enabled', 'domain', 'private_key', and 'public_key'.
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(array $data)
|
|
|
|
{
|
|
|
|
$this->enabled = (bool)$data['enabled'];
|
|
|
|
$this->domain = $data['domain'];
|
|
|
|
$this->rpcEndpoint = $data['rpc_endpoint'];
|
2024-12-10 22:14:43 -05:00
|
|
|
$this->encryptionKeysCount = $data['encryption_keys_count'];
|
|
|
|
$this->encryptionRecordsCount = $data['encryption_records_count'];
|
2024-12-10 13:30:08 -05:00
|
|
|
$this->privateKey = $data['private_key'];
|
|
|
|
$this->publicKey = $data['public_key'];
|
2024-12-10 22:14:43 -05:00
|
|
|
$this->encryptionKeys = $data['encryption_keys'];
|
2024-12-10 13:30:08 -05:00
|
|
|
}
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
/**
|
|
|
|
* Checks if the current object is enabled.
|
|
|
|
*
|
|
|
|
* @return bool True if the object is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
public function isEnabled(): bool
|
|
|
|
{
|
|
|
|
return $this->enabled;
|
|
|
|
}
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
/**
|
|
|
|
* Retrieves the domain.
|
|
|
|
*
|
|
|
|
* @return string|null The domain.
|
|
|
|
*/
|
|
|
|
public function getDomain(): ?string
|
|
|
|
{
|
|
|
|
return $this->domain;
|
|
|
|
}
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
/**
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getRpcEndpoint(): ?string
|
|
|
|
{
|
|
|
|
return $this->rpcEndpoint;
|
|
|
|
}
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 22:14:43 -05:00
|
|
|
/**
|
|
|
|
* Retrieves the number of encryption keys.
|
|
|
|
*
|
|
|
|
* @return int The number of encryption keys.
|
|
|
|
*/
|
|
|
|
public function getEncryptionKeysCount(): int
|
|
|
|
{
|
|
|
|
return $this->encryptionKeysCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the number of encryption records.
|
|
|
|
*
|
|
|
|
* @return int The number of encryption records.
|
|
|
|
*/
|
|
|
|
public function getEncryptionRecordsCount(): int
|
|
|
|
{
|
|
|
|
return $this->encryptionRecordsCount;
|
|
|
|
}
|
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
/**
|
|
|
|
* Retrieves the private key.
|
|
|
|
*
|
|
|
|
* @return string|null The private key.
|
|
|
|
*/
|
|
|
|
public function getPrivateKey(): ?string
|
|
|
|
{
|
|
|
|
return $this->privateKey;
|
|
|
|
}
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
/**
|
|
|
|
* Retrieves the public key.
|
|
|
|
*
|
|
|
|
* @return string|null The public key.
|
|
|
|
*/
|
|
|
|
public function getPublicKey(): ?string
|
|
|
|
{
|
|
|
|
return $this->publicKey;
|
|
|
|
}
|
2024-10-30 15:12:55 -04:00
|
|
|
|
2024-12-10 13:30:08 -05:00
|
|
|
/**
|
2024-12-10 22:14:43 -05:00
|
|
|
* Retrieves the encryption keys.
|
2024-12-10 13:30:08 -05:00
|
|
|
*
|
2024-12-10 22:14:43 -05:00
|
|
|
* @return array|null The encryption keys.
|
|
|
|
*/
|
|
|
|
public function getEncryptionKeys(): ?array
|
|
|
|
{
|
|
|
|
return $this->encryptionKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
2024-12-10 13:30:08 -05:00
|
|
|
*/
|
2024-12-10 22:14:43 -05:00
|
|
|
public function getRandomEncryptionKey(): string
|
2024-12-10 13:30:08 -05:00
|
|
|
{
|
2024-12-10 22:14:43 -05:00
|
|
|
return $this->encryptionKeys[array_rand($this->encryptionKeys)];
|
2024-12-10 13:30:08 -05:00
|
|
|
}
|
|
|
|
}
|