-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathSymfonyFactory.php
46 lines (38 loc) · 1.14 KB
/
SymfonyFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Http\HttplugBundle\ClientFactory;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\HttplugClient;
/**
* @author Tobias Nyholm <[email protected]>
*
* @final
*/
class SymfonyFactory implements ClientFactory
{
/**
* @var ResponseFactoryInterface
*/
private $responseFactory;
/**
* @var StreamFactoryInterface
*/
private $streamFactory;
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
{
$this->responseFactory = $responseFactory;
$this->streamFactory = $streamFactory;
}
/**
* {@inheritdoc}
*/
public function createClient(array $config = [])
{
if (!class_exists(HttplugClient::class)) {
throw new \LogicException('To use the Symfony client you need to install the "symfony/http-client" package.');
}
return new HttplugClient(HttpClient::create($config), $this->responseFactory, $this->streamFactory);
}
}