-
Notifications
You must be signed in to change notification settings - Fork 6
Adds HTTP Client Adapter #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
485cd6a
feat: starts client adapter work
JasonTheAdams 182e32a
Merge branch 'trunk' into http-adapter
JasonTheAdams 51a5130
Merge branch 'trunk' into http-adapter
JasonTheAdams c06c468
refactor: rename file to use PSR-4 autoloading
JasonTheAdams 845407a
chore: adds WordPress stubs to PHPStan
JasonTheAdams d0b9208
fix: corrects type issues
JasonTheAdams d7ef812
chore: cleans up phpstan file
JasonTheAdams f7ec38f
feat: adds nyholm/psr7 package for psr17 factory
JasonTheAdams 8010654
feat: adds HTTPlug discovery strategy
JasonTheAdams 4e0247f
feat: adds PSR17 discoverability
JasonTheAdams 3998eb7
refactor: renames class
JasonTheAdams 581de9e
refactor: removes stream args
JasonTheAdams 5c66fde
feat: updates to PHP AI Client 0.2.0
JasonTheAdams 4e80b89
feat: implements ClientWithOptionsInterface
JasonTheAdams de7de24
refactor: switches to using NetworkException
JasonTheAdams 7943ed6
refactor: cleans up unnecessary conditions code
JasonTheAdams 7c5d022
Merge branch 'trunk' into http-adapter
felixarntz 990111a
Use consistent YAML formatting in PHPStan config.
felixarntz acd0e8b
Fix PHPStan errors after updates.
felixarntz a68e34c
Temp folder rename to fix incorrect casing.
felixarntz bf54101
Fix folder name.
felixarntz 167aeb6
Fix PHP warning.
felixarntz c50d84b
Fix bug in HTTP client discovery implementation.
felixarntz a8aaf95
Wire up HTTP client discovery implementation.
felixarntz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| <?php | ||
| /** | ||
| * WordPress AI Client Discovery Strategy | ||
| * | ||
| * @package WordPress\AI_Client | ||
| * @since n.e.x.t | ||
| */ | ||
|
|
||
| namespace WordPress\AI_Client\HTTP; | ||
|
|
||
| use Http\Discovery\Psr18ClientDiscovery; | ||
| use Http\Discovery\Strategy\DiscoveryStrategy; | ||
| use Nyholm\Psr7\Factory\Psr17Factory; | ||
| use Psr\Http\Client\ClientInterface; | ||
|
|
||
| /** | ||
| * Discovery strategy for WordPress HTTP client. | ||
| * | ||
| * @since n.e.x.t | ||
| */ | ||
| class WP_AI_Client_Discovery_Strategy implements DiscoveryStrategy { | ||
|
|
||
| /** | ||
| * Initialize and register the discovery strategy. | ||
| * | ||
| * @since n.e.x.t | ||
| * @return void | ||
| */ | ||
| public static function init() { | ||
| // Check if discovery is available. | ||
| if ( ! class_exists( '\Http\Discovery\Psr18ClientDiscovery' ) ) { | ||
| return; | ||
| } | ||
|
|
||
| // Register our discovery strategy. | ||
| Psr18ClientDiscovery::prependStrategy( self::class ); | ||
| } | ||
|
|
||
| /** | ||
| * Get candidates for discovery. | ||
| * | ||
| * @param string $type The type of discovery. | ||
| * | ||
| * @return array<array<string, mixed>> | ||
| */ | ||
| public static function getCandidates( $type ) { | ||
| // PSR-18 HTTP Client. | ||
| if ( ClientInterface::class === $type ) { | ||
| return array( | ||
| array( | ||
| 'class' => array( __CLASS__, 'createWordPressClient' ), | ||
| 'condition' => array( | ||
| WordPress_HTTP_Client::class, | ||
| Psr17Factory::class, | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| // PSR-17 factories - Nyholm's Psr17Factory implements all of them. | ||
| $psr17_factories = array( | ||
| 'Psr\Http\Message\RequestFactoryInterface', | ||
| 'Psr\Http\Message\ResponseFactoryInterface', | ||
| 'Psr\Http\Message\ServerRequestFactoryInterface', | ||
| 'Psr\Http\Message\StreamFactoryInterface', | ||
| 'Psr\Http\Message\UploadedFileFactoryInterface', | ||
| 'Psr\Http\Message\UriFactoryInterface', | ||
| ); | ||
|
|
||
| if ( in_array( $type, $psr17_factories, true ) ) { | ||
| return array( | ||
| array( | ||
| 'class' => Psr17Factory::class, | ||
| 'condition' => Psr17Factory::class, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| return array(); | ||
| } | ||
|
|
||
| /** | ||
| * Create an instance of the WordPress HTTP client. | ||
| * | ||
| * @return WordPress_HTTP_Client | ||
| */ | ||
| public static function createWordPressClient() { | ||
| $psr17_factory = new Psr17Factory(); | ||
| return new WordPress_HTTP_Client( | ||
| $psr17_factory, // Response factory. | ||
| $psr17_factory // Stream factory. | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.