* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXF\Mail\Service; /** * Mail Service API Key Identity Implementation * * API key authentication for transactional mail services. * * @since 2025.05.01 */ class ServiceIdentityApiKey implements IServiceIdentityApiKey { /** * @param string $apiKey API key * @param string|null $apiKeyId Optional API key identifier */ public function __construct( private string $apiKey, private ?string $apiKeyId = null, ) {} /** * Creates from array data * * @since 2025.05.01 * * @param array $data * * @return self */ public static function fromArray(array $data): self { return new self( $data['apiKey'] ?? '', $data['apiKeyId'] ?? null, ); } /** * @inheritDoc */ public function getType(): string { return self::TYPE_APIKEY; } /** * @inheritDoc */ public function getApiKey(): string { return $this->apiKey; } /** * @inheritDoc */ public function getApiKeyId(): ?string { return $this->apiKeyId; } /** * @inheritDoc */ public function jsonSerialize(): array { return array_filter([ 'type' => self::TYPE_APIKEY, 'apiKeyId' => $this->apiKeyId, // API key intentionally omitted from serialization for security ], fn($v) => $v !== null); } }