| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Facile\OpenIDClient\Issuer\Metadata\Provider; |
| 6 |
|
| 7 |
use Facile\OpenIDClient\Exception\ExceptionInterface; |
| 8 |
use Facile\OpenIDClient\Exception\RuntimeException; |
| 9 |
use Override; |
| 10 |
|
| 11 |
use function array_filter; |
| 12 |
|
| 13 |
final class RemoteProvider implements RemoteProviderInterface |
| 14 |
{ |
| 15 |
|
| 16 |
private array $providers; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function __construct(array $providers) |
| 22 |
{ |
| 23 |
$this->providers = $providers; |
| 24 |
} |
| 25 |
|
| 26 |
#[Override] |
| 27 |
public function isAllowedUri(string $uri): bool |
| 28 |
{ |
| 29 |
return true; |
| 30 |
} |
| 31 |
|
| 32 |
#[Override] |
| 33 |
public function fetch(string $uri): array |
| 34 |
{ |
| 35 |
$lastException = null; |
| 36 |
|
| 37 |
$providers = array_filter($this->providers, static fn(RemoteProviderInterface $provider): bool => $provider->isAllowedUri($uri)); |
| 38 |
|
| 39 |
foreach ($providers as $provider) { |
| 40 |
try { |
| 41 |
return $provider->fetch($uri); |
| 42 |
} catch (ExceptionInterface $e) { |
| 43 |
$lastException = $e; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
throw new RuntimeException('Unable to fetch issuer metadata', 0, $lastException); |
| 48 |
} |
| 49 |
} |