1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Manticoresearch\Transport; |
5
|
|
|
|
6
|
|
|
use Http\Discovery\MessageFactoryDiscovery; |
|
|
|
|
7
|
|
|
|
8
|
|
|
use Manticoresearch\Connection; |
9
|
|
|
use Manticoresearch\Exceptions\ConnectionException; |
10
|
|
|
use Manticoresearch\Exceptions\ResponseException; |
11
|
|
|
use Manticoresearch\Request; |
12
|
|
|
use Manticoresearch\Response; |
13
|
|
|
use Manticoresearch\Transport; |
14
|
|
|
|
15
|
|
|
use Http\Discovery\HttpClientDiscovery; |
|
|
|
|
16
|
|
|
use Psr\Log\LoggerInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class PhpHttp |
20
|
|
|
* @package Manticoresearch\Transport |
21
|
|
|
*/ |
22
|
|
|
class PhpHttp extends Transport implements TransportInterface |
23
|
|
|
{ |
24
|
|
|
protected $client; |
25
|
|
|
protected $messageFactory; |
26
|
|
|
/** |
27
|
|
|
* PhpHttp constructor. |
28
|
|
|
* @param Connection|null $connection |
29
|
|
|
* @param LoggerInterface|null $logger |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
public function __construct(Connection $connection = null, LoggerInterface $logger = null) |
33
|
|
|
{ |
34
|
|
|
$this->client = HttpClientDiscovery::find(); |
35
|
|
|
$this->messageFactory = MessageFactoryDiscovery::find(); |
36
|
|
|
parent::__construct($connection, $logger); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function execute(Request $request, $params = []) |
40
|
|
|
{ |
41
|
|
|
$connection = $this->getConnection(); |
42
|
|
|
|
43
|
|
|
$url = $this->connection->getConfig('scheme') . '://' . $connection->getHost() . ':' . $connection->getPort() |
44
|
|
|
. $connection->getPath(); |
45
|
|
|
$endpoint = $request->getPath(); |
46
|
|
|
$url .= $endpoint; |
47
|
|
|
$url = $this->setupURI($url, $request->getQuery()); |
|
|
|
|
48
|
|
|
$method = $request->getMethod(); |
49
|
|
|
|
50
|
|
|
$headers = $connection->getHeaders(); |
51
|
|
|
$headers['Content-Type'] = $request->getContentType(); |
52
|
|
|
$data = $request->getBody(); |
53
|
|
|
if (!empty($data)) { |
54
|
|
|
if (is_array($data)) { |
55
|
|
|
$content = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
56
|
|
|
} else { |
57
|
|
|
$content = $data; |
58
|
|
|
} |
59
|
|
|
} else { |
60
|
|
|
$content = ''; |
61
|
|
|
} |
62
|
|
|
$start = microtime(true); |
63
|
|
|
$message = $this->messageFactory->createRequest($method, $url, $headers, $content); |
64
|
|
|
try { |
65
|
|
|
$responsePSR = $this->client->sendRequest($message); |
66
|
|
|
} catch (\Exception $e) { |
67
|
|
|
throw new ConnectionException($e->getMessage(), $request); |
68
|
|
|
} |
69
|
|
|
$end = microtime(true); |
70
|
|
|
$status = $responsePSR->getStatusCode(); |
71
|
|
|
$responseString = $responsePSR->getBody(); |
72
|
|
|
|
73
|
|
|
if (isset($params['responseClass'])) { |
74
|
|
|
$responseClass = $params['responseClass']; |
75
|
|
|
$responseClassParams = isset($params['responseClassParams'])?$params['responseClassParams']:[]; |
76
|
|
|
$response = new $responseClass($responseString, $status, $responseClassParams); |
77
|
|
|
} else { |
78
|
|
|
$response = new Response($responseString, $status); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$time = $end-$start; |
82
|
|
|
$response->setTime($time); |
83
|
|
|
$response->setTransportInfo([ |
84
|
|
|
'url' => $url, |
85
|
|
|
'headers' => $headers, |
86
|
|
|
'body' => $request->getBody() |
87
|
|
|
]); |
88
|
|
|
$this->logger->debug('Request body:', [ |
89
|
|
|
'connection' => $connection->getConfig(), |
90
|
|
|
'payload'=> $request->getBody() |
91
|
|
|
]); |
92
|
|
|
$this->logger->info('Request:', [ |
93
|
|
|
'url' => $url, |
94
|
|
|
'status' => $status, |
95
|
|
|
'time' => $time, |
96
|
|
|
]); |
97
|
|
|
$this->logger->debug('Response body:', $response->getResponse()); |
98
|
|
|
|
99
|
|
|
if ($response->hasError()) { |
100
|
|
|
$this->logger->error('Response:', [ |
101
|
|
|
'url' => $url, |
102
|
|
|
'error' => $response->getError(), |
103
|
|
|
'payload' => $request->getBody(), |
104
|
|
|
]); |
105
|
|
|
throw new ResponseException($request, $response); |
106
|
|
|
} |
107
|
|
|
return $response; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths