1 | <?php |
||
21 | abstract class AbstractApi extends VersionableRequestMaker |
||
22 | { |
||
23 | /** |
||
24 | * The HTTP client. |
||
25 | * |
||
26 | * @author Andrea Marco Sartori |
||
27 | * @var Cerbero\FluentApi\Clients\ClientInterface |
||
28 | */ |
||
29 | protected $client; |
||
30 | |||
31 | /** |
||
32 | * The resource inflector. |
||
33 | * |
||
34 | * @author Andrea Marco Sartori |
||
35 | * @var Cerbero\FluentApi\Inflectors\ResourceInflectorInterface |
||
36 | */ |
||
37 | protected $inflector; |
||
38 | |||
39 | /** |
||
40 | * The latest resource invoked. |
||
41 | * |
||
42 | * @var Cerbero\FluentApi\AbstractResource|null |
||
43 | */ |
||
44 | protected $resource; |
||
45 | |||
46 | /** |
||
47 | * Set the dependencies. |
||
48 | * |
||
49 | * @author Andrea Marco Sartori |
||
50 | * @param string|null $version |
||
51 | * @param Cerbero\FluentApi\Clients\ClientInterface|null $client |
||
52 | * @param Cerbero\FluentApi\Inflectors\ResourceInflectorInterface|null $inflector |
||
53 | * @return void |
||
|
|||
54 | */ |
||
55 | public function __construct( |
||
65 | |||
66 | /** |
||
67 | * Dynamically resolve resources. |
||
68 | * |
||
69 | * @author Andrea Marco Sartori |
||
70 | * @param string $name |
||
71 | * @param array $parameters |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function __call($name, array $parameters) |
||
84 | |||
85 | /** |
||
86 | * Retrieve the base URL. |
||
87 | * |
||
88 | * @author Andrea Marco Sartori |
||
89 | * @return string |
||
90 | */ |
||
91 | abstract public function getUrl(); |
||
92 | |||
93 | /** |
||
94 | * Retrieve the resource to call by inflecting the given name. |
||
95 | * |
||
96 | * @author Andrea Marco Sartori |
||
97 | * @param string $name |
||
98 | * @return Cerbero\FluentApi\Resources\ResourceInterface |
||
99 | */ |
||
100 | protected function inflectResource($name) |
||
114 | |||
115 | /** |
||
116 | * Retrieve the resource inflector. |
||
117 | * |
||
118 | * @return Cerbero\FluentApi\Inflectors\ResourceInflectorInterface |
||
119 | */ |
||
120 | public function getInflector() |
||
124 | |||
125 | /** |
||
126 | * Retrieve the default inflector. |
||
127 | * |
||
128 | * @author Andrea Marco Sartori |
||
129 | * @return Cerbero\FluentApi\Inflectors\ResourceInflectorInterface |
||
130 | */ |
||
131 | protected function defaultInflector() |
||
135 | |||
136 | /** |
||
137 | * Set the resource inflector. |
||
138 | * |
||
139 | * @author Andrea Marco Sartori |
||
140 | * @param Cerbero\FluentApi\Inflectors\ResourceInflectorInterface $inflector |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function setInflector(ResourceInflectorInterface $inflector) |
||
149 | |||
150 | /** |
||
151 | * Perform a synchronous call to the eventual endpoint. |
||
152 | * |
||
153 | * @return Psr\Http\Message\ResponseInterface |
||
154 | */ |
||
155 | public function call() |
||
159 | |||
160 | /** |
||
161 | * Perform an HTTP call by using the client. |
||
162 | * |
||
163 | * @param Closure|null $success |
||
164 | * @param Closure|null $failure |
||
165 | * @return mixed |
||
166 | */ |
||
167 | private function performCall(Closure $success = null, Closure $failure = null) |
||
181 | |||
182 | /** |
||
183 | * Perform an asynchronous call to the eventual endpoint. |
||
184 | * |
||
185 | * @param Closure $success |
||
186 | * @param Closure|null $failure |
||
187 | * @return mixed |
||
188 | */ |
||
189 | public function then(Closure $success, Closure $failure = null) |
||
197 | |||
198 | /** |
||
199 | * Retrieve the body of the response as a JSON object. |
||
200 | * |
||
201 | * @return \StdClass |
||
202 | */ |
||
203 | public function toJson() |
||
207 | |||
208 | /** |
||
209 | * Retrieve the decoded response body. |
||
210 | * |
||
211 | * @param boolean $toArray |
||
212 | * @return \StdClass|array |
||
213 | */ |
||
214 | private function decodeBody($toArray = false) |
||
220 | |||
221 | /** |
||
222 | * Retrieve the body of the response as an array. |
||
223 | * |
||
224 | * @return array |
||
225 | */ |
||
226 | public function toArray() |
||
230 | |||
231 | /** |
||
232 | * Retrieve the request to pass through resources. |
||
233 | * |
||
234 | * @return Cerbero\FluentApi\Requests\Request |
||
235 | */ |
||
236 | public function getRequest() |
||
240 | |||
241 | /** |
||
242 | * Set the HTTP client. |
||
243 | * |
||
244 | * @author Andrea Marco Sartori |
||
245 | * @param Cerbero\FluentApi\Clients\ClientInterface $client |
||
246 | * @return $this |
||
247 | */ |
||
248 | public function setClient(ClientInterface $client) |
||
254 | |||
255 | /** |
||
256 | * Retrieve the HTTP client. |
||
257 | * |
||
258 | * @author Andrea Marco Sartori |
||
259 | * @return Cerbero\FluentApi\Clients\ClientInterface |
||
260 | */ |
||
261 | public function getClient() |
||
265 | |||
266 | /** |
||
267 | * Retrieve the default HTTP client to use if none is provided. |
||
268 | * |
||
269 | * @author Andrea Marco Sartori |
||
270 | * @return Cerbero\FluentApi\Clients\ClientInterface |
||
271 | */ |
||
272 | protected function defaultClient() |
||
276 | } |
||
277 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.