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