Skip to content

Commit 6d67f34

Browse files
committed
Add allCandidates() and discoveries() methods
1 parent 380da62 commit 6d67f34

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/Contracts/Implementations/Psr18/ClientsContract.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ interface ClientsContract extends ImplementationContract
1818
*/
1919
public static function add(CandidateEntity $candidate): void;
2020

21+
/**
22+
* Return all potential candidates, including those that cannot be instantiated automatically.
23+
*/
24+
public static function allCandidates(): CandidatesCollection;
25+
2126
/**
2227
* Return the candidates collection.
2328
*/
@@ -28,6 +33,13 @@ public static function candidates(): CandidatesCollection;
2833
*/
2934
public static function discover(): ?ClientInterface;
3035

36+
/**
37+
* Returns an array with all discovered implementations.
38+
*
39+
* @return CandidateEntity[]
40+
*/
41+
public static function discoveries(): array;
42+
3143
/**
3244
* Prefer a package over all others.
3345
*

src/Implementations/Psr18/Clients.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,32 @@
1313

1414
final class Clients extends Implementation implements ClientsContract
1515
{
16-
private static ?CandidatesCollection $candidates = null;
17-
private static ?ClientInterface $singleton = null;
18-
private static ?ClientInterface $using = null;
16+
private static ?CandidatesCollection $candidates = null;
17+
private static ?CandidatesCollection $extendedCandidates = null;
18+
private static ?ClientInterface $singleton = null;
19+
private static ?ClientInterface $using = null;
1920

2021
public static function add(CandidateEntity $candidate): void
2122
{
2223
parent::add($candidate);
2324
self::use(null);
2425
}
2526

27+
/**
28+
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
29+
*/
30+
public static function allCandidates(): CandidatesCollection
31+
{
32+
if (null !== self::$extendedCandidates) {
33+
return self::$extendedCandidates;
34+
}
35+
36+
self::$extendedCandidates = CandidatesCollection::create();
37+
self::$extendedCandidates->set(self::candidates());
38+
39+
return self::$extendedCandidates;
40+
}
41+
2642
/**
2743
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
2844
*/
@@ -129,6 +145,11 @@ public static function discover(): ?ClientInterface
129145
return Discover::httpClient();
130146
}
131147

148+
public static function discoveries(): array
149+
{
150+
return Discover::httpClients();
151+
}
152+
132153
public static function prefer(string $package): void
133154
{
134155
self::$candidates ??= CandidatesCollection::create();

0 commit comments

Comments
 (0)