1 | <?php |
||
2 | |||
3 | namespace Facile\CrossbarHTTPPublisherBundle\Publisher; |
||
4 | |||
5 | use GuzzleHttp\Client as GuzzleClient; |
||
6 | |||
7 | /** |
||
8 | * Class Factory |
||
9 | * @package Facile\CrossbarHTTPPublisherBundle\Publisher |
||
10 | */ |
||
11 | class Factory |
||
12 | { |
||
13 | /** |
||
14 | * @param bool|string $hostname |
||
15 | */ |
||
16 | public function createPublisher( |
||
17 | string $protocol, |
||
18 | string $host, |
||
19 | int $port, |
||
20 | string $path, |
||
21 | ?string $key, |
||
22 | ?string $secret, |
||
23 | $hostname, |
||
24 | 3 | bool $ignoreSsl = false |
|
25 | ): Publisher { |
||
26 | 3 | $config = []; |
|
27 | |||
28 | 3 | $config['base_url'] = sprintf( |
|
29 | 3 | '%s://%s:%s%s', |
|
30 | 3 | $protocol, |
|
31 | 3 | $host, |
|
32 | 3 | $port, |
|
33 | 3 | $path |
|
34 | ); |
||
35 | 3 | $config['base_uri'] = $config['base_url']; // Guzzle 6 compat |
|
36 | |||
37 | 3 | $config['headers']['Content-Type'] = 'application/json'; |
|
38 | |||
39 | 3 | if (null !== $hostname) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
40 | $config['headers']['Host'] = $hostname; |
||
41 | } |
||
42 | |||
43 | 3 | if ($ignoreSsl) { |
|
44 | 3 | $config['verify'] = false; |
|
45 | } |
||
46 | |||
47 | 3 | if (defined('GuzzleHttp\ClientInterface::VERSION')) { |
|
48 | @trigger_error('Guzzle versions before 7 are deprecated.', E_USER_DEPRECATED); |
||
49 | 3 | } |
|
50 | |||
51 | $guzzleClient = new GuzzleClient($config); |
||
52 | |||
53 | return new Publisher($guzzleClient, $key, $secret); |
||
54 | } |
||
55 | } |
||
56 |