refactor: split service into ServiceBase and LiveService

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-10-07 21:49:31 -04:00
parent eea9b5630a
commit 4e12d41ee9
18 changed files with 649 additions and 516 deletions
+10 -10
View File
@@ -106,7 +106,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
return $list;
}
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?Service
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?ServiceBase
{
$serviceData = $this->serviceStore->fetch($tenantId, $userId, $identifier);
if ($serviceData === null) {
@@ -116,9 +116,9 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
return $serviceInstance;
}
public function serviceFindByAddress(string $tenantId, string $userId, string $address): ?Service
public function serviceFindByAddress(string $tenantId, string $userId, string $address): ?ServiceBase
{
/** @var Service[] $services */
/** @var ServiceBase[] $services */
$services = $this->serviceList($tenantId, $userId);
foreach ($services as $service) {
if ($service->hasAddress($address)) {
@@ -133,14 +133,14 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
return $this->serviceStore->extant($tenantId, $userId, $identifiers);
}
public function serviceFresh(): Service
public function serviceFresh(): ServiceBase
{
return new Service();
return new LiveService();
}
public function serviceCreate(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
{
if (!($service instanceof Service)) {
if (!($service instanceof ServiceBase)) {
throw new \InvalidArgumentException('Service must be instance of IMAP Service');
}
@@ -150,7 +150,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
{
if (!($service instanceof Service)) {
if (!($service instanceof ServiceBase)) {
throw new \InvalidArgumentException('Service must be instance of IMAP Service');
}
@@ -160,7 +160,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
{
if (!($service instanceof Service)) {
if (!($service instanceof ServiceBase)) {
return false;
}
@@ -185,7 +185,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
$startTime = microtime(true);
try {
if (!($service instanceof Service)) {
if (!($service instanceof ServiceBase)) {
throw new \InvalidArgumentException('Service must be an instance of IMAP Service');
}
// augment the service with any provided test options (e.g. override location or credentials)
@@ -193,7 +193,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
// Attempt to authenticate and list mailboxes as a connectivity check
$live = new LiveMailService($service);
$mailboxes = iterator_to_array($live->collectionList());
$mailboxes = $live->collectionList();
$latency = (int) round((microtime(true) - $startTime) * 1000);