Repository navigation
Conversation
HttpFactory is a concrete class, so consumers such as a service provider or an API client cannot type against an abstraction or have a factory injected. Add HttpFactoryInterface with createHttp(), let HttpFactory implement it, and add HttpFactoryAwareInterface and HttpFactoryAwareTrait. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of Changes
HttpFactoryis a concrete class without an interface, so consumers (the CMS service provider from joomla/joomla-cms#47692, oauth2, github-api, …) cannot type against an abstraction or have a factory injected through an Aware interface.This adds:
Joomla\Http\HttpFactoryInterfacewithcreateHttp(array|\ArrayAccess $options = [], array|string|null $adapters = null): Http;Joomla\Http\HttpFactoryAwareInterface(setHttpFactory(?HttpFactoryInterface $httpFactory = null): void);Joomla\Http\HttpFactoryAwareTrait(the setter and a protectedgetHttpFactory()that throwsUnexpectedValueExceptionwhen no factory was set);HttpFactory implements HttpFactoryInterface, with a newcreateHttp()that delegates togetHttp().getHttp()keeps its untyped signature, so subclasses are not affected.Alternative to #80. The interfaces and the trait have the same API as there (
createHttp(), so code written against #80 keeps working). The differences:HttpFactoryactually implements the interface, which #80 leaves out (without that no instance of the interface exists in the package); the@sincetags are__DEPLOY_VERSION__(#80 has a broken docblock inHttpFactoryInterface,4.1.0on a line of its own); tests and docs are added. If you prefer to merge #80, theHttpFactorypart, tests and docs of this PR can be applied on top of it instead.As in #80 (and as in database, di and model for their aware traits), the trait gets a
trait.unusedentry in the PHPStan baseline, since nothing insrc/uses it.Testing Instructions
Tests/HttpFactoryAwareTest.php(new):HttpFactoryis anHttpFactoryInterface;createHttp()returns a client with the given options, and throwsRuntimeExceptionwhen no transport is available; the trait returns the factory that was set and throwsUnexpectedValueExceptionwhen none was.Documentation Changes Required
docs/classes/HttpFactory.md: new section "Depending on the factory" on the interface, the aware interface and the trait.🤖 Generated with Claude Code