1 | <?php |
||
27 | abstract class AbstractRequest implements RequestInterface |
||
28 | { |
||
29 | /** |
||
30 | * The request parameters |
||
31 | * |
||
32 | * @var \Symfony\Component\HttpFoundation\ParameterBag |
||
33 | */ |
||
34 | protected $parameters; |
||
35 | |||
36 | /** |
||
37 | * The request client |
||
38 | * |
||
39 | * @var \GuzzleHttp\ClientInterface |
||
40 | */ |
||
41 | protected $httpClient; |
||
42 | |||
43 | /** |
||
44 | * The HTTP request object |
||
45 | * |
||
46 | * @var \Symfony\Component\HttpFoundation\Request |
||
47 | */ |
||
48 | protected $httpRequest; |
||
49 | |||
50 | /** |
||
51 | * An associated ResponseInterface |
||
52 | * |
||
53 | * @var ResponseInterface |
||
54 | */ |
||
55 | protected $response; |
||
56 | |||
57 | /** |
||
58 | * Create a new Request |
||
59 | * |
||
60 | * @param ClientInterface $httpClient A Guzzle client to make API calls with |
||
61 | * @param HttpRequest $httpRequest A Symfony HTTP request object |
||
62 | */ |
||
63 | 18 | public function __construct(ClientInterface $httpClient, HttpRequest $httpRequest) |
|
69 | |||
70 | /** |
||
71 | * Initialize the request with parameters |
||
72 | * |
||
73 | * Any unknown parameters passed will be ignored |
||
74 | * |
||
75 | * @param array $parameters An associative array of parameters |
||
76 | * |
||
77 | * @return $this |
||
78 | * @throws RuntimeException |
||
79 | */ |
||
80 | 39 | public function initialize(array $parameters = []) |
|
92 | |||
93 | /** |
||
94 | * Get all parameters as an associative array |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | 9 | public function getParameters() |
|
102 | |||
103 | /** |
||
104 | * Get a single parameter |
||
105 | * |
||
106 | * @param string $key The parameter key |
||
107 | * @return mixed |
||
108 | */ |
||
109 | 15 | protected function getParameter($key) |
|
113 | |||
114 | /** |
||
115 | * Set a single parameter |
||
116 | * |
||
117 | * @param string $key The parameter key |
||
118 | * @param mixed $value The value to set |
||
119 | * @return AbstractRequest Provides a fluent interface |
||
120 | */ |
||
121 | 24 | protected function setParameter($key, $value) |
|
131 | |||
132 | /** |
||
133 | * Set the username parameter |
||
134 | * |
||
135 | * @param string $value Username to set |
||
136 | * @return AbstractRequest |
||
137 | */ |
||
138 | 21 | public function setUsername($value) |
|
142 | |||
143 | /** |
||
144 | * Get the username parameter |
||
145 | * |
||
146 | * @return mixed |
||
147 | */ |
||
148 | 6 | public function getUsername() |
|
152 | |||
153 | /** |
||
154 | * Set the password parameter |
||
155 | * |
||
156 | * @param string $value The value to set |
||
157 | * @return AbstractRequest |
||
158 | */ |
||
159 | 12 | public function setPassword($value) |
|
163 | |||
164 | /** |
||
165 | * Get password parameter |
||
166 | * |
||
167 | * @return mixed |
||
168 | */ |
||
169 | 3 | public function getPassword() |
|
173 | |||
174 | /** |
||
175 | * Send the request |
||
176 | * |
||
177 | * @return ResponseInterface |
||
178 | */ |
||
179 | 12 | public function send() |
|
185 | |||
186 | /** |
||
187 | * Validate the request |
||
188 | * |
||
189 | * This method is called internally by the client to avoid wasting time with an API call |
||
190 | * when the request is clearly invalid |
||
191 | * |
||
192 | * @param string ... a variable length list of required parameters |
||
193 | * @throws InvalidRequestException |
||
194 | */ |
||
195 | 6 | public function validate() |
|
204 | |||
205 | /** |
||
206 | * Get the associated response |
||
207 | * |
||
208 | * @return ResponseInterface |
||
209 | */ |
||
210 | 6 | public function getResponse() |
|
218 | } |
||
219 |