1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TelegramBot\Api\Http; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Mime\Part\DataPart; |
|
|
|
|
6
|
|
|
use Symfony\Component\Mime\Part\Multipart\FormDataPart; |
|
|
|
|
7
|
|
|
use Symfony\Contracts\HttpClient\Exception\ExceptionInterface; |
|
|
|
|
8
|
|
|
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; |
|
|
|
|
9
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface as SymfonyHttpClientInterface; |
|
|
|
|
10
|
|
|
use TelegramBot\Api\HttpException; |
11
|
|
|
|
12
|
|
|
class SymfonyHttpClient extends AbstractHttpClient |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var SymfonyHttpClientInterface |
16
|
|
|
*/ |
17
|
|
|
private $http; |
18
|
|
|
|
19
|
|
|
public function __construct(SymfonyHttpClientInterface $http) |
20
|
|
|
{ |
21
|
|
|
$this->http = $http; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @inheritDoc |
26
|
|
|
*/ |
27
|
|
|
protected function doRequest($url, array $data = null) |
28
|
|
|
{ |
29
|
|
|
$options = []; |
30
|
|
|
if ($data) { |
31
|
|
|
$method = 'POST'; |
32
|
|
|
|
33
|
|
|
$data = array_filter($data); |
34
|
|
|
foreach ($data as &$value) { |
35
|
|
|
if ($value instanceof \CURLFile) { |
36
|
|
|
$value = DataPart::fromPath($value->getFilename()); |
37
|
|
|
} elseif (!\is_string($value) && !\is_array($value)) { |
38
|
|
|
$value = (string) $value; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
$formData = new FormDataPart($data); |
42
|
|
|
|
43
|
|
|
$options['headers'] = $formData->getPreparedHeaders()->toArray(); |
44
|
|
|
$options['body'] = $formData->toIterable(); |
45
|
|
|
} else { |
46
|
|
|
$method = 'GET'; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$response = $this->http->request($method, $url, $options); |
50
|
|
|
|
51
|
|
|
try { |
52
|
|
|
return $response->toArray(); |
53
|
|
|
} catch (ExceptionInterface $exception) { |
54
|
|
|
if ($exception instanceof HttpExceptionInterface) { |
55
|
|
|
$response = $exception->getResponse()->toArray(false); |
56
|
|
|
$message = array_key_exists('description', $response) ? $response['description'] : $exception->getMessage(); |
57
|
|
|
$parameters = array_key_exists('parameters', $response) ? $response['parameters'] : []; |
58
|
|
|
} else { |
59
|
|
|
$message = $exception->getMessage(); |
60
|
|
|
$parameters = []; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
throw new HttpException($message, $exception->getCode(), $exception, $parameters); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritDoc |
69
|
|
|
*/ |
70
|
|
|
protected function doDownload($url) |
71
|
|
|
{ |
72
|
|
|
try { |
73
|
|
|
return $this->http->request('GET', $url)->getContent(); |
74
|
|
|
} catch (ExceptionInterface $exception) { |
75
|
|
|
throw new HttpException($exception->getMessage(), $exception->getCode(), $exception); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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