1 | <?php |
||
14 | class SimpleRequest implements Request { |
||
15 | |||
16 | private string $action; |
||
|
|||
17 | |||
18 | private array $params = []; |
||
19 | |||
20 | private array $headers = []; |
||
21 | |||
22 | /** |
||
23 | * @param string $action The API action. |
||
24 | * @param array $params The parameters for the action. |
||
25 | * @param array $headers Any extra HTTP headers to send. |
||
26 | * |
||
27 | * @throws InvalidArgumentException |
||
28 | */ |
||
29 | public function __construct( string $action, array $params = [], array $headers = [] ) { |
||
30 | if ( !is_string( $action ) ) { |
||
31 | throw new InvalidArgumentException( '$action must be string' ); |
||
32 | } |
||
33 | $this->action = $action; |
||
34 | $this->params = $params; |
||
35 | $this->headers = $headers; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return string[] |
||
40 | */ |
||
41 | public function getParams(): array { |
||
42 | return array_merge( [ 'action' => $this->action ], $this->params ); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return string[] |
||
47 | */ |
||
48 | public function getHeaders(): array { |
||
49 | return $this->headers; |
||
50 | } |
||
51 | |||
52 | } |
||
53 |