* 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; } }