Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/ClassDiscovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Http\Discovery\Exception\ClassInstantiationFailedException;
use Http\Discovery\Exception\DiscoveryFailedException;
use Http\Discovery\Exception\StrategyUnavailableException;
use Http\Discovery\Strategy\DiscoveryStrategy;

/**
* Registry that based find results on class existence.
Expand Down Expand Up @@ -51,7 +52,15 @@ protected static function findOneByType($type)
$exceptions = [];
foreach (self::$strategies as $strategy) {
try {
$candidates = call_user_func($strategy.'::getCandidates', $type);
if (is_callable($strategy)) {
$candidates = $strategy($type);
} elseif ($strategy instanceof DiscoveryStrategy) {
$candidates = $strategy->getCandidates($type);
} elseif (is_string($strategy)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we check an instance of DiscoveryStrategy too?

$candidates = call_user_func($strategy.'::getCandidates', $type);
} else {
throw new \Exception("Stratiegy must be callable, an instance of DiscoveryStrategy or at least a FQCN to a instance of a DiscoveryStrategy");
}
} catch (StrategyUnavailableException $e) {
$exceptions[] = $e;
continue;
Expand Down