Skip to content

Instantly share code, notes, and snippets.

@ovr
Last active July 14, 2019 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovr/e2505279b57012835b195e5f80ebee84 to your computer and use it in GitHub Desktop.
Save ovr/e2505279b57012835b195e5f80ebee84 to your computer and use it in GitHub Desktop.
PSR-18 HTTP-client with PSR-17 ResponseFactoryInterface for Response
<?php
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
class Client implements ClientInterface {
/**
* @var ResponseFactoryInterface
*/
private $responseFactory;
public function __construct(ResponseFactoryInterface $responseFactory)
{
$this->responseFactory = $responseFactory;
}
public function sendRequest(RequestInterface $request): ResponseInterface
{
// doing request here
$code = 200;
$phrase = 'OK';
return $this->responseFactory->createResponse($code, $phrase);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment