bindAPI/src/Entity/Panel.php

162 lines
3.0 KiB
PHP

<?php declare(strict_types=1);
namespace App\Entity;
use App\Controller\ConfigController;
use App\Controller\EncryptionController;
use Exception;
use SodiumException;
/**
*
*/
class Panel
{
/**
* @param string $name
* @param int $id
* @param string $a
* @param string $aaaa
* @param string $passphrase
* @param string $apikey
* @param string $apikeyPrefix
* @param string $self
*/
public function __construct(
private string $name,
private int $id = 0,
private string $a = '',
private string $aaaa = '',
private readonly string $passphrase = '',
private string $apikey = '',
private string $apikeyPrefix = '',
private string $self = 'no',
)
{
if ($this->passphrase) {
$configController = new ConfigController();
$encryptionController = new EncryptionController();
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
$this->apikeyPrefix = strtok(string: $this->passphrase, token: '.');
try {
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
} catch (Exception|SodiumException $e) {
die($e->getMessage() . PHP_EOL);
}
}
}
/**
* @return string
*/
public function getPassphrase(): string
{
return $this->passphrase;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return string
*/
public function getA(): string
{
return $this->a;
}
/**
* @return string
*/
public function getSelf(): string
{
return $this->self;
}
/**
* @param string $self
*/
public function setSelf(string $self): void
{
$this->self = $self;
}
/**
* @return string
*/
public function getAaaa(): string
{
return $this->aaaa;
}
/**
* @return string
*/
public function getApikey(): string
{
return $this->apikey;
}
/**
* @param string $a
*/
public function setA(string $a): void
{
$this->a = $a;
}
/**
* @param string $aaaa
*/
public function setAaaa(string $aaaa): void
{
$this->aaaa = $aaaa;
}
/**
* @return string
*/
public function getApikeyPrefix(): string
{
return $this->apikeyPrefix;
}
}