1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Http Adapter package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\HttpAdapter; |
13
|
|
|
|
14
|
|
|
use Ivory\HttpAdapter\Message\InternalRequestInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author GeLo <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class RequestsHttpAdapter extends AbstractHttpAdapter |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \Requests_Transport |
23
|
|
|
*/ |
24
|
|
|
private $transport; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \Requests_Transport|null $transport |
28
|
|
|
* @param ConfigurationInterface|null $configuration |
29
|
|
|
*/ |
30
|
1480 |
|
public function __construct(\Requests_Transport $transport = null, ConfigurationInterface $configuration = null) |
31
|
|
|
{ |
32
|
1480 |
|
parent::__construct($configuration); |
33
|
|
|
|
34
|
1480 |
|
$this->transport = $transport; |
35
|
1480 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
85 |
|
public function getName() |
41
|
|
|
{ |
42
|
85 |
|
return 'requests'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
1428 |
|
protected function sendInternalRequest(InternalRequestInterface $internalRequest) |
49
|
|
|
{ |
50
|
|
|
$options = [ |
51
|
1428 |
|
'timeout' => $this->getConfiguration()->getTimeout(), |
52
|
1428 |
|
'connect_timeout' => $this->getConfiguration()->getTimeout(), |
53
|
1428 |
|
'protocol_version' => (float) $this->getConfiguration()->getProtocolVersion(), |
54
|
1428 |
|
'follow_redirects' => 0, |
55
|
1428 |
|
'data_format' => 'body', |
56
|
1092 |
|
]; |
57
|
|
|
|
58
|
1428 |
|
if ($this->transport !== null) { |
59
|
1428 |
|
$options['transport'] = $this->transport; |
60
|
1092 |
|
} |
61
|
|
|
|
62
|
|
|
try { |
63
|
1428 |
|
$response = \Requests::request( |
64
|
1428 |
|
$uri = (string) $internalRequest->getUri(), |
65
|
1428 |
|
$this->prepareHeaders($internalRequest), |
66
|
1428 |
|
$this->prepareBody($internalRequest), |
|
|
|
|
67
|
1428 |
|
$internalRequest->getMethod(), |
68
|
|
|
$options |
69
|
1092 |
|
); |
70
|
1108 |
|
} catch (\Exception $e) { |
71
|
68 |
|
throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage()); |
72
|
|
|
} |
73
|
|
|
|
74
|
1377 |
|
return $this->getConfiguration()->getMessageFactory()->createResponse( |
75
|
1416 |
|
$response->status_code, |
76
|
1377 |
|
sprintf('%.1f', $response->protocol_version), |
77
|
1377 |
|
$response->headers->getAll(), |
78
|
1377 |
|
$response->body |
79
|
1053 |
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: