Вікі-код для 3. Власні API методи
Сховати останніх авторів
author | version | line-number | content |
---|---|---|---|
![]() |
5.1 | 1 | {{box cssClass="floatinginfobox" title="**Зміст**"}} |
2 | {{toc/}} | ||
3 | {{/box}} | ||
![]() |
2.1 | 4 | |
![]() |
3.2 | 5 | Ви можете легко додавати власні API методи до RPC сервера. |
6 | |||
![]() |
4.1 | 7 | Для цього вам достатньо в будь-якому місці вашого додатку зробити будь-який клас який має стати API Сервісом, цей клас має реалізувати інтерфейс (% class="box code" %)Ufo\JsonRpcBundle\ApiMethod\Interfaces\IRpcService(%%). Цей інтерфейс не навʼязує класу жодної логіки, він необхідний лише для того, щоб Symfony зрозумів, що має його сприймати як сервіс, що доступний для RPC сервера. |
![]() |
3.2 | 8 | |
9 | Реалізуйте в вашому класі будь-який публічний метод і він автоматично буде доступний як API Сервіс. | ||
10 | |||
![]() |
4.1 | 11 | (% id="cke_bm_318406S" style="display:none" %) (%%)Після виконання попередніх вказівок у вас вже будуть доступні нові методи в API. За замовченням назви методів складаються з (% class="box code" %)<className>.<methodName>(%%). |
![]() |
3.2 | 12 | |
![]() |
3.5 | 13 | = Іменування класів = |
![]() |
3.2 | 14 | |
15 | В разі потреби, ви можете створити кілька класів, що будуть доступні як API Сервіси. | ||
16 | Враховуючи їх неймінги **<className>.<methodName>**, рекомендую підходити до вибору назви методу як до простої вказівки що він робить, а до назви класу як до неймспейсу API методу. | ||
17 | |||
![]() |
4.1 | 18 | (% class="box successmessage" %) |
19 | ((( | ||
![]() |
3.3 | 20 | == **Гарна практика** == |
![]() |
3.2 | 21 | |
22 | Класс **//Messenger//** містить методи **//sendEmail()//**//,** sendSms()**//,// //класс// **CartResolver** //містить методи **//addProduct()//**//,** getProducts()**//, //**calculateDiscount()**// | ||
23 | |||
24 | в API будуть доступні методи | ||
25 | |||
26 | * //**CartResolver.addProduct**// | ||
27 | * //**CartResolver.getProducts**// | ||
28 | * //**CartResolver.calculateDiscount**// | ||
29 | * **//Messenger.sendEmail//** | ||
30 | * **//Messenger.sendSms//** | ||
31 | |||
32 | Навіть просто поглянувши на назви методів зрозуміло що може робити ваш сервер. | ||
![]() |
3.4 | 33 | |
34 | Такий підхід надає можливість використовувати одноіменні методи в різних класах: | ||
35 | |||
![]() |
3.5 | 36 | * //**ProductService.create**// |
37 | * //**ProductService.getName**// | ||
38 | * //**UserService.create**// | ||
39 | * //**UserService.getName**// | ||
![]() |
4.1 | 40 | ))) |
![]() |
3.2 | 41 | |
![]() |
3.7 | 42 | = Простий старт = |
![]() |
3.2 | 43 | |
44 | Наступний приклад має продемонструвати легкість додавання ваших методів до API. | ||
45 | |||
![]() |
3.5 | 46 | (% class="row" %) |
47 | ((( | ||
48 | (% class="col-xs-12 col-sm-6" %) | ||
49 | ((( | ||
![]() |
4.1 | 50 | (% class="box" %) |
51 | ((( | ||
52 | == Код == | ||
![]() |
2.1 | 53 | |
![]() |
4.1 | 54 | (% class="code" %) |
55 | ((( | ||
56 | (% class="linenoswrapper" %) | ||
57 | ((( | ||
58 | (% class="linenos" %) | ||
59 | ((( | ||
60 | 1 | ||
61 | 2 | ||
62 | 3 | ||
63 | 4 | ||
64 | 5 | ||
65 | 6 | ||
66 | 7 | ||
67 | 8 | ||
68 | 9 | ||
69 | 10 | ||
70 | 11 | ||
71 | 12 | ||
72 | 13 | ||
73 | 14 | ||
74 | 15 | ||
75 | 16 | ||
76 | 17 | ||
77 | 18 | ||
78 | 19 | ||
79 | 20 | ||
80 | 21 | ||
81 | 22 | ||
82 | 23 | ||
83 | 24 | ||
84 | 25 | ||
85 | 26 | ||
86 | 27 | ||
87 | 28 | ||
![]() |
5.1 | 88 | 29 |
![]() |
4.1 | 89 | ))) |
![]() |
2.1 | 90 | |
![]() |
4.1 | 91 | ((( |
![]() |
5.1 | 92 | (% style="color:#bc7a00" %)<?php(%%) |
93 | (% style="color:#008000; font-weight:bold" %)**namespace**(%%) App\Api\Procedures; | ||
94 | \\(% style="color:#008000; font-weight:bold" %)**use**(%%) Ufo\JsonRpcBundle\ApiMethod\Interfaces\IRpcService; | ||
95 | \\(% style="color:#008000; font-weight:bold" %)**class**(%%) (% style="color:#0000ff; font-weight:bold" %)**ExampleApi**(%%) (% style="color:#008000; font-weight:bold" %)**implements**(%%) IRpcService | ||
![]() |
2.1 | 96 | { |
![]() |
5.1 | 97 | (% style="color:#008000; font-weight:bold" %)**public**(%%) (% style="color:#008000; font-weight:bold" %)**function**(%%) (% style="color:#0000ff" %)~_~_construct(%%)( |
98 | (% style="color:#408080; font-style:italic" %)//~/~/ connecting some dependencies to retrieve data//(%%) | ||
99 | ) {} | ||
100 | |||
101 | (% style="color:#008000; font-weight:bold" %)**public**(%%) (% style="color:#008000; font-weight:bold" %)**function**(%%) (% style="color:#0000ff" %)getUserNameByUuid(%%)( | ||
102 | string (% style="color:#19177c" %)$userId(%%) | ||
103 | )(% style="color:#666666" %):(%%) string | ||
![]() |
2.1 | 104 | { |
![]() |
5.1 | 105 | (% style="color:#408080; font-style:italic" %)//~/~/ some logic get user info by id//(%%) |
106 | (% style="color:#008000; font-weight:bold" %)**return**(%%) (% style="color:#ba2121" %)'some result'(%%); | ||
![]() |
2.1 | 107 | } |
![]() |
5.1 | 108 | |
109 | (% style="color:#008000; font-weight:bold" %)**public**(%%) (% style="color:#008000; font-weight:bold" %)**function**(%%) (% style="color:#0000ff" %)sendEmail(%%)( | ||
110 | string (% style="color:#19177c" %)$email(%%), | ||
111 | string (% style="color:#19177c" %)$text(%%), | ||
112 | string (% style="color:#19177c" %)$subject(%%) (% style="color:#666666" %)=(%%) (% style="color:#ba2121" %)'Message without subject'(%%) | ||
113 | )(% style="color:#666666" %):(%%) bool | ||
![]() |
2.1 | 114 | { |
![]() |
5.1 | 115 | (% style="color:#408080; font-style:italic" %)//~/~/ some logic send email//(%%) |
116 | (% style="color:#008000; font-weight:bold" %)**return**(%%) (% style="color:#008000; font-weight:bold" %)**true**(%%); | ||
![]() |
2.1 | 117 | } |
118 | } | ||
![]() |
4.1 | 119 | ))) |
120 | ))) | ||
121 | ))) | ||
122 | ))) | ||
![]() |
3.2 | 123 | |
![]() |
3.8 | 124 | Праворуч приклад документації, що сервер згенерує по цьому класу. |
![]() |
3.7 | 125 | |
![]() |
4.1 | 126 | Основна інформація щодо назв параметрів, їх типів та опціональності отримується завдяки (% class="box code" %)ReflectionClass(%%), важливим є порядок аргументів методу, їх typehint. |
![]() |
3.5 | 127 | ))) |
![]() |
3.2 | 128 | |
![]() |
3.5 | 129 | (% class="col-xs-12 col-sm-6" %) |
130 | ((( | ||
![]() |
4.1 | 131 | (% class="box" %) |
132 | ((( | ||
133 | == Документація == | ||
134 | |||
135 | (% class="code" %) | ||
136 | ((( | ||
137 | (% class="linenoswrapper" %) | ||
138 | ((( | ||
139 | (% class="linenos" %) | ||
140 | ((( | ||
141 | 1 | ||
142 | 2 | ||
143 | 3 | ||
144 | 4 | ||
145 | 5 | ||
146 | 6 | ||
147 | 7 | ||
148 | 8 | ||
149 | 9 | ||
150 | 10 | ||
151 | 11 | ||
152 | 12 | ||
153 | 13 | ||
154 | 14 | ||
155 | 15 | ||
156 | 16 | ||
157 | 17 | ||
158 | 18 | ||
159 | 19 | ||
160 | 20 | ||
161 | 21 | ||
162 | 22 | ||
163 | 23 | ||
164 | 24 | ||
165 | 25 | ||
166 | 26 | ||
167 | 27 | ||
168 | 28 | ||
169 | 29 | ||
170 | 30 | ||
171 | 31 | ||
172 | 32 | ||
173 | 33 | ||
174 | 34 | ||
175 | 35 | ||
176 | 36 | ||
177 | 37 | ||
178 | 38 | ||
179 | 39 | ||
180 | 40 | ||
181 | 41 | ||
182 | 42 | ||
183 | 43 | ||
184 | 44 | ||
![]() |
5.1 | 185 | 45 |
![]() |
4.1 | 186 | ))) |
187 | |||
188 | ((( | ||
![]() |
3.2 | 189 | { |
![]() |
5.1 | 190 | (% style="color:#008000; font-weight:bold" %)**"methods"**(%%): { |
191 | (% style="color:#008000; font-weight:bold" %)**"ExampleApi.getUserNameByUuid"**(%%): { | ||
192 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"ExampleApi.getUserNameByUuid"(%%), | ||
193 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)""(%%), | ||
194 | (% style="color:#008000; font-weight:bold" %)**"parameters"**(%%): { | ||
195 | (% style="color:#008000; font-weight:bold" %)**"userId"**(%%): { | ||
196 | (% style="color:#008000; font-weight:bold" %)**"type"**(%%): (% style="color:#ba2121" %)"string"(%%), | ||
197 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"userId"(%%), | ||
198 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)""(%%), | ||
199 | (% style="color:#008000; font-weight:bold" %)**"optional"**(%%): (% style="color:#008000; font-weight:bold" %)**false**(%%) | ||
![]() |
3.2 | 200 | } |
201 | }, | ||
![]() |
5.1 | 202 | (% style="color:#008000; font-weight:bold" %)**"returns"**(%%): (% style="color:#ba2121" %)"string"(%%), |
203 | (% style="color:#008000; font-weight:bold" %)**"responseFormat"**(%%): (% style="color:#ba2121" %)"string"(%%) | ||
![]() |
3.2 | 204 | }, |
![]() |
5.1 | 205 | (% style="color:#008000; font-weight:bold" %)**"ExampleApi.sendEmail"**(%%): { |
206 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"ExampleApi.sendEmail"(%%), | ||
207 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)""(%%), | ||
208 | (% style="color:#008000; font-weight:bold" %)**"parameters"**(%%): { | ||
209 | (% style="color:#008000; font-weight:bold" %)**"email"**(%%): { | ||
210 | (% style="color:#008000; font-weight:bold" %)**"type"**(%%): (% style="color:#ba2121" %)"string"(%%), | ||
211 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"email"(%%), | ||
212 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)""(%%), | ||
213 | (% style="color:#008000; font-weight:bold" %)**"optional"**(%%): (% style="color:#008000; font-weight:bold" %)**false**(%%) | ||
![]() |
3.2 | 214 | }, |
![]() |
5.1 | 215 | (% style="color:#008000; font-weight:bold" %)**"text"**(%%): { |
216 | (% style="color:#008000; font-weight:bold" %)**"type"**(%%): (% style="color:#ba2121" %)"string"(%%), | ||
217 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"text"(%%), | ||
218 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)""(%%), | ||
219 | (% style="color:#008000; font-weight:bold" %)**"optional"**(%%): (% style="color:#008000; font-weight:bold" %)**false**(%%) | ||
![]() |
3.2 | 220 | }, |
![]() |
5.1 | 221 | (% style="color:#008000; font-weight:bold" %)**"subject"**(%%): { |
222 | (% style="color:#008000; font-weight:bold" %)**"type"**(%%): (% style="color:#ba2121" %)"string"(%%), | ||
223 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"subject"(%%), | ||
224 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)""(%%), | ||
225 | (% style="color:#008000; font-weight:bold" %)**"optional"**(%%): (% style="color:#008000; font-weight:bold" %)**true**(%%), | ||
226 | (% style="color:#008000; font-weight:bold" %)**"default"**(%%): (% style="color:#ba2121" %)"Message without subject"(%%) | ||
![]() |
3.2 | 227 | } |
228 | }, | ||
![]() |
5.1 | 229 | (% style="color:#008000; font-weight:bold" %)**"returns"**(%%): (% style="color:#ba2121" %)"boolean"(%%), |
230 | (% style="color:#008000; font-weight:bold" %)**"responseFormat"**(%%): (% style="color:#ba2121" %)"boolean"(%%) | ||
![]() |
3.2 | 231 | } |
232 | } | ||
233 | } | ||
![]() |
3.5 | 234 | ))) |
235 | ))) | ||
![]() |
4.1 | 236 | ))) |
237 | ))) | ||
238 | ))) | ||
239 | ))) | ||
![]() |
3.5 | 240 | |
![]() |
3.2 | 241 | Тепер можемо зробити POST запити на обидва нових метода API і подивитися на результат. |
242 | |||
![]() |
3.7 | 243 | == **POST запити** == |
![]() |
3.2 | 244 | |
![]() |
3.7 | 245 | (% class="row" %) |
246 | ((( | ||
247 | (% class="col-xs-12 col-sm-6" %) | ||
248 | ((( | ||
![]() |
4.1 | 249 | (% class="box" %) |
250 | ((( | ||
251 | Request | ||
252 | |||
253 | (% class="code" %) | ||
254 | ((( | ||
255 | (% class="linenoswrapper" %) | ||
256 | ((( | ||
257 | (% class="linenos" %) | ||
258 | ((( | ||
259 | 1 | ||
260 | 2 | ||
261 | 3 | ||
262 | 4 | ||
263 | 5 | ||
264 | 6 | ||
![]() |
5.1 | 265 | 7 |
![]() |
4.1 | 266 | ))) |
267 | |||
268 | ((( | ||
![]() |
3.2 | 269 | { |
![]() |
5.1 | 270 | (% style="color:#008000; font-weight:bold" %)**"id"**(%%): (% style="color:#ba2121" %)"example_request"(%%), |
271 | (% style="color:#008000; font-weight:bold" %)**"method"**(%%): (% style="color:#ba2121" %)"ExampleApi.getUserNameByUuid"(%%), | ||
272 | (% style="color:#008000; font-weight:bold" %)**"params"**(%%): { | ||
273 | (% style="color:#008000; font-weight:bold" %)**"userId"**(%%): (% style="color:#ba2121" %)"1111"(%%) | ||
![]() |
3.2 | 274 | } |
275 | } | ||
![]() |
3.7 | 276 | ))) |
![]() |
4.1 | 277 | ))) |
278 | ))) | ||
279 | ))) | ||
280 | ))) | ||
![]() |
3.2 | 281 | |
![]() |
3.7 | 282 | (% class="col-xs-12 col-sm-6" %) |
283 | ((( | ||
![]() |
4.1 | 284 | (% class="box" %) |
285 | ((( | ||
286 | Response | ||
287 | |||
288 | (% class="code" %) | ||
289 | ((( | ||
290 | (% class="linenoswrapper" %) | ||
291 | ((( | ||
292 | (% class="linenos" %) | ||
293 | ((( | ||
294 | 1 | ||
295 | 2 | ||
296 | 3 | ||
297 | 4 | ||
![]() |
5.1 | 298 | 5 |
![]() |
4.1 | 299 | ))) |
300 | |||
301 | ((( | ||
![]() |
3.2 | 302 | { |
![]() |
5.1 | 303 | (% style="color:#008000; font-weight:bold" %)**"id"**(%%): (% style="color:#ba2121" %)"example_request"(%%), |
304 | (% style="color:#008000; font-weight:bold" %)**"result"**(%%): (% style="color:#ba2121" %)"some result"(%%), | ||
305 | (% style="color:#008000; font-weight:bold" %)**"jsonrpc"**(%%): (% style="color:#ba2121" %)"2.0"(%%) | ||
![]() |
3.2 | 306 | } |
![]() |
4.1 | 307 | ))) |
308 | ))) | ||
309 | ))) | ||
310 | ))) | ||
![]() |
3.2 | 311 | |
312 | |||
![]() |
3.7 | 313 | |
314 | ))) | ||
315 | ))) | ||
316 | |||
317 | (% class="row" %) | ||
318 | ((( | ||
319 | (% class="col-xs-12 col-sm-6" %) | ||
320 | ((( | ||
![]() |
4.1 | 321 | (% class="box" %) |
322 | ((( | ||
323 | Request | ||
324 | |||
325 | (% class="code" %) | ||
326 | ((( | ||
327 | (% class="linenoswrapper" %) | ||
328 | ((( | ||
329 | (% class="linenos" %) | ||
330 | ((( | ||
331 | 1 | ||
332 | 2 | ||
333 | 3 | ||
334 | 4 | ||
335 | 5 | ||
336 | 6 | ||
337 | 7 | ||
338 | 8 | ||
![]() |
5.1 | 339 | 9 |
![]() |
4.1 | 340 | ))) |
341 | |||
342 | ((( | ||
![]() |
3.2 | 343 | { |
![]() |
5.1 | 344 | (% style="color:#008000; font-weight:bold" %)**"id"**(%%): (% style="color:#ba2121" %)"example_request"(%%), |
345 | (% style="color:#008000; font-weight:bold" %)**"method"**(%%): (% style="color:#ba2121" %)"ExampleApi.sendEmail"(%%), | ||
346 | (% style="color:#008000; font-weight:bold" %)**"params"**(%%): { | ||
347 | (% style="color:#008000; font-weight:bold" %)**"email"**(%%): (% style="color:#ba2121" %)"user@example.com"(%%), | ||
348 | (% style="color:#008000; font-weight:bold" %)**"subject"**(%%): (% style="color:#ba2121" %)"This is test mail"(%%), | ||
349 | (% style="color:#008000; font-weight:bold" %)**"text"**(%%): (% style="color:#ba2121" %)"Hi! This is test send mail by API"(%%) | ||
![]() |
3.2 | 350 | } |
351 | } | ||
![]() |
3.7 | 352 | ))) |
![]() |
4.1 | 353 | ))) |
354 | ))) | ||
355 | ))) | ||
356 | ))) | ||
![]() |
3.2 | 357 | |
![]() |
3.7 | 358 | (% class="col-xs-12 col-sm-6" %) |
359 | ((( | ||
![]() |
4.1 | 360 | (% class="box" %) |
361 | ((( | ||
362 | Response | ||
363 | |||
364 | (% class="code" %) | ||
365 | ((( | ||
366 | (% class="linenoswrapper" %) | ||
367 | ((( | ||
368 | (% class="linenos" %) | ||
369 | ((( | ||
370 | 1 | ||
371 | 2 | ||
372 | 3 | ||
373 | 4 | ||
![]() |
5.1 | 374 | 5 |
![]() |
4.1 | 375 | ))) |
376 | |||
377 | ((( | ||
![]() |
3.2 | 378 | { |
![]() |
5.1 | 379 | (% style="color:#008000; font-weight:bold" %)**"id"**(%%): (% style="color:#ba2121" %)"example_request"(%%), |
380 | (% style="color:#008000; font-weight:bold" %)**"result"**(%%): (% style="color:#008000; font-weight:bold" %)**true**(%%), | ||
381 | (% style="color:#008000; font-weight:bold" %)**"jsonrpc"**(%%): (% style="color:#ba2121" %)"2.0"(%%) | ||
![]() |
3.2 | 382 | } |
![]() |
3.7 | 383 | ))) |
384 | ))) | ||
![]() |
4.1 | 385 | ))) |
386 | ))) | ||
387 | ))) | ||
388 | ))) | ||
![]() |
3.7 | 389 | |
![]() |
3.10 | 390 | (% class="box warningmessage" %) |
391 | ((( | ||
392 | Для спрощення сприйняття документації, всі подальші приклади буду надавати на одному методі (//**sendEmail**//) | ||
393 | ))) | ||
![]() |
3.7 | 394 | |
![]() |
3.10 | 395 | = Опис методів та параметрів = |
396 | |||
![]() |
3.9 | 397 | Документатор спирається на всі наявні дані, що належать методу та його аргументам (назви, типи вхідних і вихідних даних, докблоки). Тож, опис методів і параметрів можна збагатити за рахунок докблоків. |
![]() |
3.7 | 398 | |
![]() |
3.9 | 399 | Додамо опис методу і параметрів. |
![]() |
3.7 | 400 | |
![]() |
3.10 | 401 | (% class="row" %) |
402 | ((( | ||
403 | (% class="col-xs-12 col-sm-6" %) | ||
404 | ((( | ||
![]() |
4.1 | 405 | (% class="box" %) |
406 | ((( | ||
407 | == Код == | ||
![]() |
3.7 | 408 | |
![]() |
4.1 | 409 | (% class="code" %) |
410 | ((( | ||
411 | (% class="linenoswrapper" %) | ||
412 | ((( | ||
413 | (% class="linenos" %) | ||
414 | ((( | ||
415 | 1 | ||
416 | 2 | ||
417 | 3 | ||
418 | 4 | ||
419 | 5 | ||
420 | 6 | ||
421 | 7 | ||
422 | 8 | ||
423 | 9 | ||
424 | 10 | ||
425 | 11 | ||
426 | 12 | ||
427 | 13 | ||
428 | 14 | ||
429 | 15 | ||
430 | 16 | ||
431 | 17 | ||
432 | 18 | ||
433 | 19 | ||
434 | 20 | ||
![]() |
5.1 | 435 | 21 |
![]() |
4.1 | 436 | ))) |
437 | |||
438 | ((( | ||
![]() |
5.1 | 439 | (% style="color:#bc7a00" %)<?php(%%) |
440 | (% style="color:#408080; font-style:italic" %)//~/~/ ...// | ||
441 | |||
442 | (% style="color:#ba2121; font-style:italic" %)///~*~* | ||
![]() |
4.1 | 443 | ~* A method for sending an email message |
444 | ~* @param string $email The email address | ||
445 | ~* @param string $text Message body | ||
446 | ~* @param string $subject Optional message subject parameter | ||
447 | ~* @return bool | ||
![]() |
5.1 | 448 | *///(%%) |
449 | (% style="color:#008000; font-weight:bold" %)**public**(%%) (% style="color:#008000; font-weight:bold" %)**function**(%%) (% style="color:#0000ff" %)sendEmail(%%)( | ||
450 | string (% style="color:#19177c" %)$email(%%), | ||
451 | string (% style="color:#19177c" %)$text(%%), | ||
452 | string (% style="color:#19177c" %)$subject(%%) (% style="color:#666666" %)=(%%) (% style="color:#ba2121" %)'Message without subject'(%%) | ||
453 | )(% style="color:#666666" %):(%%) bool | ||
![]() |
3.10 | 454 | { |
![]() |
5.1 | 455 | (% style="color:#408080; font-style:italic" %)//~/~/ some logic send email//(%%) |
456 | (% style="color:#008000; font-weight:bold" %)**return**(%%) (% style="color:#008000; font-weight:bold" %)**true**(%%); | ||
![]() |
3.10 | 457 | } |
![]() |
5.1 | 458 | \\(% style="color:#408080; font-style:italic" %)//~/~/ ...// |
![]() |
4.1 | 459 | ))) |
460 | ))) | ||
461 | ))) | ||
462 | ))) | ||
![]() |
3.10 | 463 | |
464 | Зверніть увагу на документацію, тепер в ній відображається додаткова інформація про метод і його параметри. | ||
465 | |||
466 | |||
467 | ))) | ||
468 | |||
469 | (% class="col-xs-12 col-sm-6" %) | ||
470 | ((( | ||
![]() |
4.1 | 471 | (% class="box" %) |
472 | ((( | ||
473 | == Документація == | ||
474 | |||
475 | (% class="code" %) | ||
476 | ((( | ||
477 | (% class="linenoswrapper" %) | ||
478 | ((( | ||
479 | (% class="linenos" %) | ||
480 | ((( | ||
481 | 1 | ||
482 | 2 | ||
483 | 3 | ||
484 | 4 | ||
485 | 5 | ||
486 | 6 | ||
487 | 7 | ||
488 | 8 | ||
489 | 9 | ||
490 | 10 | ||
491 | 11 | ||
492 | 12 | ||
493 | 13 | ||
494 | 14 | ||
495 | 15 | ||
496 | 16 | ||
497 | 17 | ||
498 | 18 | ||
499 | 19 | ||
500 | 20 | ||
501 | 21 | ||
502 | 22 | ||
503 | 23 | ||
504 | 24 | ||
505 | 25 | ||
506 | 26 | ||
507 | 27 | ||
508 | 28 | ||
509 | 29 | ||
510 | 30 | ||
![]() |
5.1 | 511 | 31 |
![]() |
4.1 | 512 | ))) |
513 | |||
514 | ((( | ||
![]() |
3.10 | 515 | { |
![]() |
5.1 | 516 | (% style="color:#008000; font-weight:bold" %)**"methods"**(%%): { |
517 | (% style="color:#008000; font-weight:bold" %)**"ExampleApi.sendEmail"**(%%): { | ||
518 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"ExampleApi.sendEmail"(%%), | ||
519 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)"A method for sending an email message"(%%), | ||
520 | (% style="color:#008000; font-weight:bold" %)**"parameters"**(%%): { | ||
521 | (% style="color:#008000; font-weight:bold" %)**"email"**(%%): { | ||
522 | (% style="color:#008000; font-weight:bold" %)**"type"**(%%): (% style="color:#ba2121" %)"string"(%%), | ||
523 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"email"(%%), | ||
524 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)"The email address"(%%), | ||
525 | (% style="color:#008000; font-weight:bold" %)**"optional"**(%%): (% style="color:#008000; font-weight:bold" %)**false**(%%) | ||
![]() |
3.10 | 526 | }, |
![]() |
5.1 | 527 | (% style="color:#008000; font-weight:bold" %)**"text"**(%%): { |
528 | (% style="color:#008000; font-weight:bold" %)**"type"**(%%): (% style="color:#ba2121" %)"string"(%%), | ||
529 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"text"(%%), | ||
530 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)"Message body"(%%), | ||
531 | (% style="color:#008000; font-weight:bold" %)**"optional"**(%%): (% style="color:#008000; font-weight:bold" %)**false**(%%) | ||
![]() |
3.10 | 532 | }, |
![]() |
5.1 | 533 | (% style="color:#008000; font-weight:bold" %)**"subject"**(%%): { |
534 | (% style="color:#008000; font-weight:bold" %)**"type"**(%%): (% style="color:#ba2121" %)"string"(%%), | ||
535 | (% style="color:#008000; font-weight:bold" %)**"name"**(%%): (% style="color:#ba2121" %)"subject"(%%), | ||
536 | (% style="color:#008000; font-weight:bold" %)**"description"**(%%): (% style="color:#ba2121" %)"Optional message subject parameter"(%%), | ||
537 | (% style="color:#008000; font-weight:bold" %)**"optional"**(%%): (% style="color:#008000; font-weight:bold" %)**true**(%%), | ||
538 | (% style="color:#008000; font-weight:bold" %)**"default"**(%%): (% style="color:#ba2121" %)"Message without subject"(%%) | ||
![]() |
3.10 | 539 | } |
540 | }, | ||
![]() |
5.1 | 541 | (% style="color:#008000; font-weight:bold" %)**"returns"**(%%): (% style="color:#ba2121" %)"boolean"(%%), |
542 | (% style="color:#008000; font-weight:bold" %)**"responseFormat"**(%%): (% style="color:#ba2121" %)"boolean"(%%) | ||
![]() |
3.10 | 543 | } |
544 | } | ||
545 | } | ||
546 | ))) | ||
547 | ))) | ||
![]() |
4.1 | 548 | ))) |
549 | ))) | ||
550 | ))) | ||
551 | ))) | ||
![]() |
3.10 | 552 | |
553 | = RPC attributes = | ||
554 | |||
![]() |
4.1 | 555 | Для більш гнучкого налаштування ваших методів API JsonRpcBundle використовує такий інструмент як [[php атрибути>>url:https://www.php.net/manual/en/language.attributes.overview.php]]. |
![]() |
3.10 | 556 | |
557 | За допомогою спеціалізованих атрибутів ви можете: | ||
558 | |||
559 | * налаштувати псевдоніми для методів; | ||
![]() |
3.13 | 560 | * вказати формат відповіді для методів (якщо відповідь у вигляді масива, обʼєкта або колекції обʼєктів); |
![]() |
3.10 | 561 | * налаштувати валідацію вхідних параметрів; |
562 | * налаштувати кешування відповідей. | ||
563 | |||
![]() |
3.13 | 564 | Докладніше про ці атрибути: |
![]() |
3.10 | 565 | |
![]() |
4.1 | 566 | (% class="xtree" data-checkboxes="false" data-contextmenu="false" data-draganddrop="false" data-edges="true" data-finder="false" data-icons="true" data-responsive="true" data-url="/bin/get/docs/JsonRpcBundle/add_rpc_service/WebHome?outputSyntax=plain&sheet=XWiki.DocumentTree&root=document%3A" %) |
567 | ((( | ||
![]() |
5.1 | 568 | |
![]() |
4.1 | 569 | ))) |
570 | |||
![]() |
3.13 | 571 | (% class="wikigeneratedid" id="H41F44143543243443E43D45643C438API43C43544243E434456432" %) |
572 |