Files
provider_imap/lib/Providers/ServiceIdentityBasic.php
2026-03-28 12:43:42 -04:00

75 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace KTXM\ProviderImap\Providers;
use KTXF\Resource\Provider\ResourceServiceIdentityBasic;
/**
* IMAP Service Basic Identity
*
* Username / password (or token) authentication.
*/
class ServiceIdentityBasic implements ResourceServiceIdentityBasic
{
public function __construct(
private string $identity = '',
private string $secret = '',
) {}
public function toStore(): array
{
return [
'type' => self::TYPE_BASIC,
'identity' => $this->identity,
'secret' => $this->secret,
];
}
public function fromStore(array $data): static
{
return new static(
identity: $data['identity'] ?? '',
secret: $data['secret'] ?? '',
);
}
public function jsonSerialize(): array
{
return [
'type' => self::TYPE_BASIC,
'identity' => $this->identity,
// Secret intentionally omitted from serialisation
];
}
public function jsonDeserialize(array|string $data): static
{
if (is_string($data)) {
$data = json_decode($data, true);
}
$this->identity = $data['identity'] ?? '';
$this->secret = $data['secret'] ?? '';
return $this;
}
public function type(): string
{
return self::TYPE_BASIC;
}
public function getIdentity(): string { return $this->identity; }
public function setIdentity(string $v): void { $this->identity = $v; }
public function getSecret(): string { return $this->secret; }
public function setSecret(string $v): void { $this->secret = $v; }
}