74 lines
1.6 KiB
PHP
74 lines
1.6 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use App\Controller\ConfigController;
|
|
use App\Controller\EncryptionController;
|
|
use Exception;
|
|
|
|
class Apikey
|
|
{
|
|
public function __construct(
|
|
private int $id = 0,
|
|
private string $name = '',
|
|
private string $apikey = '',
|
|
private string $apikeyPrefix = '',
|
|
private readonly string $passphrase = '',
|
|
private string $createdAt = ''
|
|
)
|
|
{
|
|
if ($this->passphrase) {
|
|
$configController = new ConfigController(quiet: true);
|
|
$encryptionController = new EncryptionController();
|
|
|
|
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
|
|
|
|
$this->apikey = strtok(string: $this->passphrase, token: '.');
|
|
|
|
try {
|
|
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
|
|
} catch (Exception $e) {
|
|
exit($e->getMessage() . PHP_EOL);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getCreatedAt(): string
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function getApikey(): string
|
|
{
|
|
return $this->apikey;
|
|
}
|
|
|
|
public function getApikeyPrefix(): string
|
|
{
|
|
return $this->apikeyPrefix;
|
|
}
|
|
|
|
|
|
public function getId(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
|
|
public function setApikey(string $apikey): void
|
|
{
|
|
$this->apikey = $apikey;
|
|
}
|
|
|
|
|
|
public function setName(string $name): void
|
|
{
|
|
$this->name = $name;
|
|
}
|
|
|
|
} |