refactor: unify streaming
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user