1 | <?php |
||
19 | class Builder |
||
20 | { |
||
21 | const METHOD_DELETE = 0; |
||
22 | const METHOD_GET = 1; |
||
23 | const METHOD_PATCH = 2; |
||
24 | const METHOD_POST = 3; |
||
25 | const METHOD_PUT = 4; |
||
26 | |||
27 | /** @var boolean */ |
||
28 | private $asJson; |
||
29 | |||
30 | /** @var null|string|array */ |
||
31 | private $data; |
||
32 | |||
33 | /** @var array|ResponseBehaviourInterface[] */ |
||
34 | private $defaultResponseBehaviours; |
||
35 | |||
36 | /** @var Merge */ |
||
37 | private $merge; |
||
38 | |||
39 | /** @var int */ |
||
40 | private $method; |
||
41 | |||
42 | /** @var array */ |
||
43 | private $parameters; |
||
44 | |||
45 | /** @var Request */ |
||
46 | private $request; |
||
47 | |||
48 | /** @var array|ResponseBehaviourInterface[] */ |
||
49 | private $responseBehaviours; |
||
50 | |||
51 | /** @var string */ |
||
52 | private $url; |
||
53 | |||
54 | /** |
||
55 | * @param Request $request |
||
56 | * @param Merge $merge |
||
57 | * @param array|ResponseBehaviourInterface[] $defaultResponseBehaviours |
||
58 | */ |
||
59 | public function __construct(Request $request, Merge $merge, array $defaultResponseBehaviours = array()) |
||
66 | |||
67 | /** |
||
68 | * @return Response |
||
69 | * @throws Exception|RuntimeException |
||
70 | */ |
||
71 | public function andFetchTheResponse() |
||
99 | |||
100 | /** |
||
101 | * @return $this |
||
102 | */ |
||
103 | public function asJson() |
||
111 | |||
112 | /** |
||
113 | * @param bool $alsoTheDefaults |
||
114 | * @return $this |
||
115 | */ |
||
116 | public function reset($alsoTheDefaults = false) |
||
127 | |||
128 | /** |
||
129 | * @param string $url |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function onTheUrl($url) |
||
138 | |||
139 | /** |
||
140 | * @param null|string|array $data |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function withTheData($data) |
||
149 | |||
150 | /** |
||
151 | * @param HeaderLineInterface $line |
||
152 | * @return $this |
||
153 | */ |
||
154 | public function withTheHeaderLine(HeaderLineInterface $line) |
||
160 | |||
161 | /** |
||
162 | * @param OptionInterface $option |
||
163 | * @return $this |
||
164 | */ |
||
165 | public function withTheOption(OptionInterface $option) |
||
171 | |||
172 | /** |
||
173 | * @param array $parameters |
||
174 | * @return $this |
||
175 | */ |
||
176 | public function withTheParameters(array $parameters) |
||
182 | |||
183 | /** |
||
184 | * @param string $line |
||
185 | * @return $this |
||
186 | */ |
||
187 | public function withTheRawHeaderLine($line) |
||
193 | |||
194 | /** |
||
195 | * @param string $key |
||
196 | * @param string $value |
||
197 | * @return $this |
||
198 | */ |
||
199 | public function withTheRawOption($key, $value) |
||
205 | |||
206 | /** |
||
207 | * @param ResponseBehaviourInterface $behaviour |
||
208 | * @return $this |
||
209 | */ |
||
210 | public function withTheResponseBehaviour(ResponseBehaviourInterface $behaviour) |
||
216 | |||
217 | //@todo better nameing? |
||
218 | // callDelete |
||
219 | /** |
||
220 | * @return $this |
||
221 | */ |
||
222 | public function useDelete() |
||
228 | |||
229 | /** |
||
230 | * @return $this |
||
231 | */ |
||
232 | public function useGet() |
||
238 | |||
239 | /** |
||
240 | * @return $this |
||
241 | */ |
||
242 | public function usePatch() |
||
248 | |||
249 | /** |
||
250 | * @return $this |
||
251 | */ |
||
252 | public function usePost() |
||
258 | |||
259 | /** |
||
260 | * @return $this |
||
261 | */ |
||
262 | public function usePut() |
||
268 | |||
269 | /** |
||
270 | * @param array|ResponseBehaviourInterface[] $behaviours |
||
271 | * @param Response $response |
||
272 | * @return Response |
||
273 | */ |
||
274 | private function applyBehaviours(array $behaviours, Response $response) |
||
282 | |||
283 | /** |
||
284 | * @param mixed $data |
||
285 | * @param boolean $convertIt |
||
286 | * @return mixed |
||
287 | */ |
||
288 | private function convertToJsonIfNeeded($data, $convertIt) |
||
292 | |||
293 | /** |
||
294 | * @param string $method |
||
295 | * @param Request $request |
||
296 | * @param string $url |
||
297 | * @param array $parameters |
||
298 | * @param mixed $data |
||
299 | * @return Response |
||
300 | * @throws RuntimeException |
||
301 | */ |
||
302 | private function fetchResponseFromRequestOrThrowRuntimeException($method, Request $request, $url, array $parameters, $data) |
||
328 | } |
||
329 |