Last active
July 14, 2019 09:11
-
-
Save ovr/e2505279b57012835b195e5f80ebee84 to your computer and use it in GitHub Desktop.
PSR-18 HTTP-client with PSR-17 ResponseFactoryInterface for Response
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
<?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