generated from Nodarx/template
feat: initial version
Signed-off-by: Sebastian Krupinski <root@LAPTOP-7DVOR6NC>
This commit was merged in pull request #1.
This commit is contained in:
83
lib/Providers/ServiceSettings.php
Normal file
83
lib/Providers/ServiceSettings.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderImapMail\Providers;
|
||||
|
||||
enum ServiceMode: string
|
||||
{
|
||||
case Live = 'live';
|
||||
case Cached = 'cached';
|
||||
}
|
||||
|
||||
enum CacheSyncStrategy: string
|
||||
{
|
||||
case Manual = 'manual';
|
||||
case Interval = 'interval';
|
||||
case Push = 'push';
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-service operational settings for the IMAP provider.
|
||||
*
|
||||
* - debug: Attach a PSR-3 logger to the IMAP client when true
|
||||
* - mode: live (all reads/writes hit IMAP) | cached (reads from MongoDB)
|
||||
* - cacheSync: How the cache is kept fresh (only relevant in cached mode)
|
||||
*/
|
||||
class ServiceSettings
|
||||
{
|
||||
public function __construct(
|
||||
private bool $debug = false,
|
||||
private ServiceMode $mode = ServiceMode::Live,
|
||||
private CacheSyncStrategy $cacheSync = CacheSyncStrategy::Interval,
|
||||
) {}
|
||||
|
||||
// ── Serialisation ────────────────────────────────────────────────────────
|
||||
|
||||
public function toStore(): array
|
||||
{
|
||||
return [
|
||||
'debug' => $this->debug,
|
||||
'mode' => $this->mode->value,
|
||||
'cacheSync' => $this->cacheSync->value,
|
||||
];
|
||||
}
|
||||
|
||||
public function fromStore(array $data): static
|
||||
{
|
||||
$this->debug = $data['debug'] ?? false;
|
||||
$this->mode = ServiceMode::from($data['mode'] ?? ServiceMode::Live->value);
|
||||
$this->cacheSync = CacheSyncStrategy::from($data['cacheSync'] ?? CacheSyncStrategy::Interval->value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return $this->toStore();
|
||||
}
|
||||
|
||||
public function jsonDeserialize(array|string $data): static
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
return $this->fromStore($data);
|
||||
}
|
||||
|
||||
// ── Accessors ────────────────────────────────────────────────────────────
|
||||
|
||||
public function getDebug(): bool { return $this->debug; }
|
||||
public function setDebug(bool $v): static { $this->debug = $v; return $this; }
|
||||
|
||||
public function getMode(): ServiceMode { return $this->mode; }
|
||||
public function setMode(ServiceMode $v): static { $this->mode = $v; return $this; }
|
||||
|
||||
public function getCacheSync(): CacheSyncStrategy { return $this->cacheSync; }
|
||||
public function setCacheSync(CacheSyncStrategy $v): static { $this->cacheSync = $v; return $this; }
|
||||
}
|
||||
Reference in New Issue
Block a user