AbstractClientDiscoveryStrategy
- Since
- 1.1.0
- Source
wp-includes/php-ai-client/src/Providers/Http/Abstracts/AbstractClientDiscoveryStrategy.php:20
Abstract discovery strategy for HTTP client implementations.
Description
Provides a base for registering custom HTTP client implementations with HTTPlug's discovery mechanism. Subclasses must implement the createClient() method to provide their specific PSR-18 HTTP client instance using the provided Psr17Factory.
Compatibility
- WordPress
- since 1.1.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 2 of the 5 tracked releases, added in 1.1.0.
Methods · 3
- init()Initializes and registers the discovery strategy.
- getCandidates(){@inheritDoc}
- createClient()Creates an instance of the HTTP client.
Source code
abstract class AbstractClientDiscoveryStrategy implements DiscoveryStrategy{ /** * Initializes and registers the discovery strategy. * * @since 1.1.0 * * @return void */ public static function init(): void { if (!class_exists('WordPress\AiClientDependencies\Http\Discovery\Psr18ClientDiscovery')) { return; } Psr18ClientDiscovery::prependStrategy(static::class); } /** * {@inheritDoc} * * @since 1.1.0 * * @param string $type The type of discovery. * @return array<array<string, mixed>> The discovery candidates. */ public static function getCandidates($type) { if (ClientInterface::class === $type) { return [['class' => static function () { $psr17Factory = new Psr17Factory(); return static::createClient($psr17Factory); }]]; } $psr17Factories = ['WordPress\AiClientDependencies\Psr\Http\Message\RequestFactoryInterface', 'WordPress\AiClientDependencies\Psr\Http\Message\ResponseFactoryInterface', 'WordPress\AiClientDependencies\Psr\Http\Message\ServerRequestFactoryInterface', 'WordPress\AiClientDependencies\Psr\Http\Message\StreamFactoryInterface', 'WordPress\AiClientDependencies\Psr\Http\Message\UploadedFileFactoryInterface', 'WordPress\AiClientDependencies\Psr\Http\Message\UriFactoryInterface']; if (in_array($type, $psr17Factories, \true)) { return [['class' => Psr17Factory::class]]; } return []; } /** * Creates an instance of the HTTP client. * * Subclasses must implement this method to return their specific * PSR-18 HTTP client instance. The provided Psr17Factory implements * all PSR-17 interfaces (RequestFactory, ResponseFactory, StreamFactory, * etc.) and can be used to satisfy client constructor dependencies. * * @since 1.1.0 * * @param Psr17Factory $psr17Factory The PSR-17 factory for creating HTTP messages. * @return ClientInterface The PSR-18 HTTP client. */ abstract protected static function createClient(Psr17Factory $psr17Factory): ClientInterface;}Changelog
Introduced in 1.1.0. Unchanged from 7.0.4 through 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/php-ai-client/src/Providers/Http/Abstracts/AbstractClientDiscoveryStrategy.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.