refactor: unify streaming
All checks were successful
Build Test / test (pull_request) Successful in 26s
JS Unit Tests / test (pull_request) Successful in 27s
PHP Unit Tests / test (pull_request) Successful in 1m8s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-03-06 22:53:08 -05:00
parent 5bfe5dd249
commit cceaf809d9
10 changed files with 205 additions and 130 deletions

View File

@@ -303,7 +303,7 @@ class Manager {
}
/**
* Discover mail service settings from identity
* Discover mail service settings from identity, yielding results as each provider completes
*
* @since 2025.05.01
*
@@ -314,12 +314,7 @@ class Manager {
* @param string|null $location Optional hostname to test directly (bypasses DNS SRV lookup)
* @param string|null $secret Optional password/token to validate discovered service
*
* @return array<string,ResourceServiceLocationInterface> Array of discovered service locations keyed by provider ID
* [
* 'jmap' => ResourceServiceLocationInterface,
* 'smtp' => ResourceServiceLocationInterface,
* // Only providers that successfully discovered (non-null)
* ]
* @return \Generator Yields providerId => ResourceServiceLocationInterface pairs as each provider completes
*/
public function serviceDiscover(
string $tenantId,
@@ -328,32 +323,28 @@ class Manager {
string $identity,
string|null $location = null,
string|null $secret = null
): array {
$locations = [];
): \Generator {
$providers = $this->providerList($tenantId, $userId, $providerId !== null ? new SourceSelector([$providerId => true]) : null);
foreach ($providers as $providerId => $provider) {
foreach ($providers as $currentProviderId => $provider) {
if (!($provider instanceof ProviderServiceDiscoverInterface)) {
continue;
}
try {
$location = $provider->serviceDiscover($tenantId, $userId, $identity, $location, $secret);
if ($location !== null) {
$locations[$providerId] = $location;
$result = $provider->serviceDiscover($tenantId, $userId, $identity, $location, $secret);
if ($result !== null) {
yield $currentProviderId => $result;
}
} catch (\Throwable $e) {
$this->logger->warning('Provider autodiscovery failed', [
'provider' => $providerId,
'provider' => $currentProviderId,
'identity' => $identity,
'error' => $e->getMessage(),
]);
}
}
return $locations;
}
/**