|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SW client http |
|
4
|
|
|
* User: moyo |
|
5
|
|
|
* Date: 2018/7/2 |
|
6
|
|
|
* Time: 3:25 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Carno\HTTP\Powered\Swoole\Chips; |
|
10
|
|
|
|
|
11
|
|
|
use Carno\HTTP\Standard\Response; |
|
12
|
|
|
use Carno\HTTP\Standard\Streams\Form; |
|
13
|
|
|
use Psr\Http\Message\RequestInterface as Request; |
|
14
|
|
|
use Swoole\Http\Client as SWHClient; |
|
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
trait Http |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param Request $request |
|
20
|
|
|
* @return array |
|
21
|
|
|
*/ |
|
22
|
|
|
private function http(Request $request) : array |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var SWHClient $http |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
$http = $this->http; |
|
29
|
|
|
|
|
30
|
|
|
// -- request init |
|
31
|
|
|
|
|
32
|
|
|
$http->setMethod($request->getMethod()); |
|
33
|
|
|
|
|
34
|
|
|
// -- net sender |
|
35
|
|
|
|
|
36
|
|
|
$executor = function ($fn) use ($http, $request) { |
|
37
|
|
|
$uri = $this->getUriPath($request->getUri()); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$stream = $request->getBody(); |
|
40
|
|
|
|
|
41
|
|
|
if ($stream instanceof Form) { |
|
42
|
|
|
foreach ($stream->files() as $name => $file) { |
|
43
|
|
|
$http->addFile($file->path(), $name); |
|
44
|
|
|
} |
|
45
|
|
|
$http->post($uri, $stream->data(), $fn); |
|
46
|
|
|
return; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($stream->getSize() > 0) { |
|
50
|
|
|
$http->setData((string)$stream); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$http->execute($uri, $fn); |
|
54
|
|
|
}; |
|
55
|
|
|
|
|
56
|
|
|
// -- net receiver |
|
57
|
|
|
|
|
58
|
|
|
$receiver = function (SWHClient $c) use ($request) { |
|
59
|
|
|
$code = $c->statusCode; |
|
60
|
|
|
$headers = (array)$c->headers; |
|
61
|
|
|
$response = $c->body; |
|
62
|
|
|
|
|
63
|
|
|
// reset cli headers !! |
|
64
|
|
|
foreach (array_keys($c->headers ?? []) as $k) { |
|
65
|
|
|
unset($c->headers[$k]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if ($code > 0) { |
|
69
|
|
|
return new Response($code, $headers, $response); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->throwing($request, $c); |
|
|
|
|
|
|
73
|
|
|
}; |
|
74
|
|
|
|
|
75
|
|
|
// -- packing |
|
76
|
|
|
|
|
77
|
|
|
return [$executor, $receiver]; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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