1 | <?php declare(strict_types=1); |
||
17 | class Artax implements Client |
||
18 | { |
||
19 | private $client; |
||
20 | |||
21 | 4 | public function __construct(ArtaxClient $client) |
|
25 | |||
26 | 2 | public function post(Url $url, Header $header, Body $body, int $flags = 0): Promise |
|
44 | |||
45 | 2 | private function getFormBody(Body $body): FormBody |
|
46 | { |
||
47 | 2 | $formBody = new FormBody(); |
|
48 | |||
49 | 2 | foreach ($body->getParameters() as $parameter) { |
|
50 | 2 | if ($parameter instanceof FieldParameter) { |
|
51 | 2 | $formBody->addField($parameter->getKey(), $parameter->getValue(), $parameter->getType()); |
|
52 | } else if ($parameter instanceof FileParameter) { |
||
53 | $formBody->addFile($parameter->getKey(), $parameter->getPath(), $parameter->getType()); |
||
54 | } else { |
||
55 | throw new Exception("Unexpected parameter type: " . get_class($parameter)); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | 2 | return $formBody; |
|
60 | } |
||
61 | |||
62 | 2 | public function get(Url $url, Header $header, array $parameters, int $flags = 0): Promise |
|
77 | |||
78 | 2 | private function buildQueryString(Parameter ...$parameters): string |
|
92 | } |
||
93 |