ClassDiscovery::findOneByType( string $type ): string|Closure

In this article

Finds a class.

Parameters

$typestringrequired

Return

string|Closure

Source

protected static function findOneByType($type)
{
    // Look in the cache
    if (null !== $class = self::getFromCache($type)) {
        return $class;
    }
    static $skipStrategy;
    $skipStrategy ?? $skipStrategy = self::safeClassExists(Strategy\GeneratedDiscoveryStrategy::class) ? \false : Strategy\GeneratedDiscoveryStrategy::class;
    $exceptions = [];
    foreach (self::$strategies as $strategy) {
        if ($skipStrategy === $strategy) {
            continue;
        }
        try {
            $candidates = $strategy::getCandidates($type);
        } catch (StrategyUnavailableException $e) {
            if (!isset(self::$deprecatedStrategies[$strategy])) {
                $exceptions[] = $e;
            }
            continue;
        }
        foreach ($candidates as $candidate) {
            if (isset($candidate['condition'])) {
                if (!self::evaluateCondition($candidate['condition'])) {
                    continue;
                }
            }
            // save the result for later use
            self::storeInCache($type, $candidate);
            return $candidate['class'];
        }
        $exceptions[] = new NoCandidateFoundException($strategy, $candidates);
    }
    throw DiscoveryFailedException::create($exceptions);
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.