1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TelegramBot\Api\Http; |
4
|
|
|
|
5
|
|
|
use Psr\Http\Client\ClientExceptionInterface; |
|
|
|
|
6
|
|
|
use Psr\Http\Client\ClientInterface; |
|
|
|
|
7
|
|
|
use Psr\Http\Message\RequestFactoryInterface; |
|
|
|
|
8
|
|
|
use TelegramBot\Api\HttpException; |
9
|
|
|
use TelegramBot\Api\InvalidJsonException; |
10
|
|
|
|
11
|
|
|
class PsrHttpClient extends AbstractHttpClient |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var ClientInterface |
15
|
|
|
*/ |
16
|
|
|
private $http; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var RequestFactoryInterface |
20
|
|
|
*/ |
21
|
|
|
private $requestFactory; |
22
|
|
|
|
23
|
|
|
public function __construct(ClientInterface $http, RequestFactoryInterface $requestFactory) |
24
|
|
|
{ |
25
|
|
|
$this->http = $http; |
26
|
|
|
$this->requestFactory = $requestFactory; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @inheritDoc |
31
|
|
|
*/ |
32
|
|
|
protected function doRequest($url, array $data = null) |
33
|
|
|
{ |
34
|
|
|
if ($data) { |
35
|
|
|
$method = 'POST'; |
36
|
|
|
} else { |
37
|
|
|
$method = 'GET'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$request = $this->requestFactory->createRequest($method, $url); |
41
|
|
|
try { |
42
|
|
|
$response = $this->http->sendRequest($request); |
43
|
|
|
} catch (ClientExceptionInterface $exception) { |
44
|
|
|
throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$content = $response->getBody()->getContents(); |
48
|
|
|
|
49
|
|
|
return self::jsonValidate($content); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritDoc |
54
|
|
|
*/ |
55
|
|
|
protected function doDownload($url) |
56
|
|
|
{ |
57
|
|
|
$request = $this->requestFactory->createRequest('GET', $url); |
58
|
|
|
|
59
|
|
|
try { |
60
|
|
|
return $this->http->sendRequest($request)->getBody()->getContents(); |
61
|
|
|
} catch (ClientExceptionInterface $exception) { |
62
|
|
|
throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $jsonString |
68
|
|
|
* @return array |
69
|
|
|
* @throws InvalidJsonException |
70
|
|
|
*/ |
71
|
|
|
private static function jsonValidate($jsonString) |
72
|
|
|
{ |
73
|
|
|
/** @var array $json */ |
74
|
|
|
$json = json_decode($jsonString, true); |
75
|
|
|
|
76
|
|
|
if (json_last_error() !== JSON_ERROR_NONE) { |
77
|
|
|
throw new InvalidJsonException(json_last_error_msg(), json_last_error()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $json; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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