Skip to content

Commit 28283e1

Browse files
committed
extract endpoints/methods from AdminApi on extractor/loader class
1 parent 8e8ac77 commit 28283e1

File tree

2 files changed

+374
-16
lines changed

2 files changed

+374
-16
lines changed

src/Configuration/Extractor.php

Lines changed: 236 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
namespace Kiboko\Plugin\Sylius\Configuration;
66

7+
use phpDocumentor\Reflection\Types\Self_;
78
use Symfony\Component\Config;
89

910
use function Kiboko\Component\SatelliteToolbox\Configuration\asExpression;
1011
use function Kiboko\Component\SatelliteToolbox\Configuration\isExpression;
1112

1213
final class Extractor implements Config\Definition\ConfigurationInterface
1314
{
14-
private static array $endpoints = [
15+
private static array $endpointsLegacy = [
1516
// Core Endpoints
1617
'channels' => [
1718
'listPerPage',
@@ -125,13 +126,221 @@ final class Extractor implements Config\Definition\ConfigurationInterface
125126
],
126127
];
127128

128-
private static array $doubleEndpoints = [
129+
private static array $endpointsAdmin = [
130+
'address' => [
131+
'get',
132+
],
133+
'adjustment' => [
134+
'listPerPage',
135+
'all',
136+
'get',
137+
],
138+
'administrator' => [
139+
'listPerPage',
140+
'all',
141+
'get',
142+
],
143+
'avatarImage' => [
144+
'get',
145+
],
146+
'catalogPromotion' => [
147+
'listPerPage',
148+
'all',
149+
'get',
150+
],
151+
'catalogPromotionTranslation' => [
152+
'get',
153+
],
154+
'channel' => [
155+
'listPerPage',
156+
'all',
157+
'get',
158+
],
159+
'country' => [
160+
'listPerPage',
161+
'all',
162+
'get',
163+
],
164+
'currency' => [
165+
'listPerPage',
166+
'all',
167+
'get',
168+
],
169+
'customer' => [
170+
'get',
171+
],
172+
'customerGroup' => [
173+
'listPerPage',
174+
'all',
175+
'get',
176+
],
177+
'exchangeRate' => [
178+
'listPerPage',
179+
'all',
180+
'get',
181+
],
182+
'locale' => [
183+
'listPerPage',
184+
'all',
185+
'get',
186+
],
187+
'order' => [
188+
'listPerPage',
189+
'all',
190+
'get',
191+
'listPaymentsPerPage',
192+
'allPayments',
193+
'listShipmentPerPage',
194+
'allShipments'
195+
],
196+
'orderItem' => [
197+
'get',
198+
],
199+
'orderItemUnit' => [
200+
'get',
201+
],
202+
'payment' => [
203+
'listPerPage',
204+
'all',
205+
'get',
206+
],
207+
'paymentMethod' => [
208+
'get',
209+
],
210+
'product' => [
211+
'listPerPage',
212+
'all',
213+
'get',
214+
],
215+
'productAssociationType' => [
216+
'listPerPage',
217+
'all',
218+
'get',
219+
],
220+
'productAssociationTypeTranslation' => [
221+
'get',
222+
],
223+
'productImage' => [
224+
'listPerPage',
225+
'all',
226+
'get',
227+
],
228+
'productOption' => [
229+
'listPerPage',
230+
'all',
231+
'get',
232+
'listValuesPerPage',
233+
'allValues',
234+
],
235+
'productOptionTranslation' => [
236+
'get',
237+
],
238+
'productOptionValue' => [
239+
'listPerPage',
240+
'all',
241+
'get',
242+
],
243+
'productReview' => [
244+
'listPerPage',
245+
'all',
246+
'get',
247+
],
248+
'productTaxon' => [
249+
'listPerPage',
250+
'all',
251+
'get',
252+
],
253+
'productTranslation' => [
254+
'get',
255+
],
256+
'productVariant' => [
257+
'listPerPage',
258+
'all',
259+
'get',
260+
],
261+
'productVariantTranslation' => [
262+
'get',
263+
],
264+
'promotion' => [
265+
'listPerPage',
266+
'all',
267+
'get',
268+
],
269+
'province' => [
270+
'listPerPage',
271+
'all',
272+
'get',
273+
],
274+
'shipment' => [
275+
'listPerPage',
276+
'all',
277+
'get',
278+
],
279+
'shippingCategory' => [
280+
'listPerPage',
281+
'all',
282+
'get',
283+
],
284+
'shippingMethod' => [
285+
'listPerPage',
286+
'all',
287+
'get',
288+
],
289+
'ShopBillingData' => [
290+
'listPerPage',
291+
'all',
292+
'get',
293+
],
294+
'taxCategory' => [
295+
'listPerPage',
296+
'all',
297+
'get',
298+
],
299+
'taxon' => [
300+
'listPerPage',
301+
'all',
302+
'get',
303+
],
304+
'taxonTranslation' => [
305+
'listPerPage',
306+
'all',
307+
'get',
308+
],
309+
'zone' => [
310+
'listPerPage',
311+
'all',
312+
'get',
313+
],
314+
'zoneMember' => [
315+
'listPerPage',
316+
'all',
317+
'get',
318+
],
319+
];
320+
321+
private static array $endpointsShop = [
322+
// Core Endpoints
323+
];
324+
325+
private static array $doubleEndpointsLegacy = [
129326
// Double resources Endpoints
130327
'productReviews',
131328
'productVariants',
132329
'promotionCoupons',
133330
];
134331

332+
private static array $doubleEndpointsAdmin = [
333+
// Double resources Endpoints
334+
'adjustment',
335+
'province',
336+
'shopBillingData',
337+
'zoneMember',
338+
];
339+
340+
private static array $doubleEndpointsShop = [
341+
// Double resources Endpoints
342+
];
343+
135344
public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder
136345
{
137346
$filters = new Search();
@@ -143,12 +352,33 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui
143352
->validate()
144353
->ifArray()
145354
->then(function (array $item) {
355+
switch($item['api_type']) {
356+
case 'admin':
357+
$endpoints = self::$endpointsAdmin;
358+
$doubleEndpoints = self::$doubleEndpointsAdmin;
359+
break;
360+
case 'shop':
361+
$endpoints = self::$endpointsShop;
362+
$doubleEndpoints = self::$doubleEndpointsShop;
363+
break;
364+
case 'legacy':
365+
$endpoints = self::$endpointsLegacy;
366+
$doubleEndpoints = self::$doubleEndpointsLegacy;
367+
break;
368+
default:
369+
$endpoints = [];
370+
$doubleEndpoints = [];
371+
break;
372+
}
373+
if (!\in_array(array_keys(array_merge($endpoints, $doubleEndpoints)), $item['type'])) {
374+
throw new \InvalidArgumentException(sprintf('the value should be one of [%s], got %s', implode(', ', array_keys($endpoints)), json_encode($item['type'], \JSON_THROW_ON_ERROR)));
375+
}
146376
if (
147-
\array_key_exists($item['type'], self::$endpoints)
148-
&& !\in_array($item['method'], self::$endpoints[$item['type']])
149-
&& !\in_array($item['type'], self::$doubleEndpoints)
377+
\array_key_exists($item['type'], $endpoints)
378+
&& !\in_array($item['method'], $endpoints[$item['type']])
379+
&& !\in_array($item['type'], $doubleEndpoints)
150380
) {
151-
throw new \InvalidArgumentException(sprintf('The value should be one of [%s], got %s.', implode(', ', self::$endpoints[$item['type']]), json_encode($item['method'], \JSON_THROW_ON_ERROR)));
381+
throw new \InvalidArgumentException(sprintf('The value should be one of [%s], got %s.', implode(', ', $endpoints[$item['type']]), json_encode($item['method'], \JSON_THROW_ON_ERROR)));
152382
}
153383

154384
return $item;

0 commit comments

Comments
 (0)