Recently I have been scratching my head over PSR-18. As a new PSR there isn’t a lot of information around it, but I saw that as a challenge. I decided to accept this challenge and build a compliant HTTP client to embrace the future of interoperability.
namespace JustSteveKing\HttpSlim; use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Client\ClientExceptionInterface; class HttpClient implements HttpClientInterface { protected ClientInterface $client; protected StreamFactoryInterface $streamFactory; protected RequestFactoryInterface $requestFactory; }
final protected function __construct( ClientInterface $client, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory ) { $this->client = $client; $this->requestFactory = $requestFactory; $this->streamFactory = $streamFactory; } public static function build( ClientInterface $client, RequestFactoryInterface $requestFactory, StreamFactoryInterface $streamFactory ): self { return new static( $client, $requestFactory, $streamFactory ); }