Skip to content

Commit ca7e08f

Browse files
committed
extract endpoints/methods from ShopApi on extractor/loader class
1 parent 28283e1 commit ca7e08f

File tree

3 files changed

+166
-30
lines changed

3 files changed

+166
-30
lines changed

src/Configuration/Extractor.php

+130-22
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ final class Extractor implements Config\Definition\ConfigurationInterface
190190
'get',
191191
'listPaymentsPerPage',
192192
'allPayments',
193-
'listShipmentPerPage',
193+
'listShipmentsPerPage',
194194
'allShipments'
195195
],
196196
'orderItem' => [
@@ -320,6 +320,128 @@ final class Extractor implements Config\Definition\ConfigurationInterface
320320

321321
private static array $endpointsShop = [
322322
// Core Endpoints
323+
'address' => [
324+
'listPerPage',
325+
'all',
326+
'get',
327+
],
328+
'adjustment' => [
329+
'listPerPage',
330+
'all',
331+
'get',
332+
],
333+
'catalogPromotion' => [
334+
'get',
335+
],
336+
'channel' => [
337+
'get',
338+
],
339+
'country' => [
340+
'listPerPage',
341+
'all',
342+
'get',
343+
],
344+
'currency' => [
345+
'listPerPage',
346+
'all',
347+
'get',
348+
],
349+
'customer' => [
350+
'get',
351+
],
352+
'locale' => [
353+
'listPerPage',
354+
'all',
355+
'get',
356+
],
357+
'order' => [
358+
'listPerPage',
359+
'all',
360+
'get',
361+
'listPaymentMethodsPerPage',
362+
'allPaymentMethods',
363+
'listShipmentMethodsPerPage',
364+
'allShipmentMethods',
365+
'listAdjustmentsPerPage',
366+
'allAdjustments',
367+
'listItemsPerPage',
368+
'allItems',
369+
],
370+
'orderItem' => [
371+
'listPerPage',
372+
'all',
373+
'get',
374+
'listAdjustmentsPerPage',
375+
'allAdjustments',
376+
],
377+
'orderItemUnit' => [
378+
'get',
379+
],
380+
'payment' => [
381+
'listPerPage',
382+
'all',
383+
'get',
384+
],
385+
'paymentMethod' => [
386+
'listPerPage',
387+
'all',
388+
'get',
389+
],
390+
'product' => [
391+
'listPerPage',
392+
'all',
393+
'get',
394+
'getBySlug',
395+
],
396+
'productImage' => [
397+
'get',
398+
],
399+
'productOption' => [
400+
'get',
401+
],
402+
'productOptionValue' => [
403+
'get',
404+
],
405+
'productReview' => [
406+
'listPerPage',
407+
'all',
408+
'get',
409+
],
410+
'productTaxon' => [
411+
'get',
412+
],
413+
'productTranslation' => [
414+
'get',
415+
],
416+
'productVariant' => [
417+
'listPerPage',
418+
'all',
419+
'get',
420+
],
421+
'productVariantTranslation' => [
422+
'get',
423+
],
424+
'shipment' => [
425+
'listPerPage',
426+
'all',
427+
'get',
428+
],
429+
'shippingMethod' => [
430+
'listPerPage',
431+
'all',
432+
'get',
433+
],
434+
'shippingMethodTranslation' => [
435+
'get',
436+
],
437+
'taxon' => [
438+
'listPerPage',
439+
'all',
440+
'get',
441+
],
442+
'taxonTranslation' => [
443+
'get',
444+
],
323445
];
324446

325447
private static array $doubleEndpointsLegacy = [
@@ -339,6 +461,8 @@ final class Extractor implements Config\Definition\ConfigurationInterface
339461

340462
private static array $doubleEndpointsShop = [
341463
// Double resources Endpoints
464+
'adjustment',
465+
'order',
342466
];
343467

344468
public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder
@@ -370,8 +494,8 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui
370494
$doubleEndpoints = [];
371495
break;
372496
}
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)));
497+
if (!\in_array($item['type'], array_merge(array_keys($endpoints), $doubleEndpoints))) {
498+
throw new \InvalidArgumentException(sprintf('the value should be one of [%s], got %s', implode(', ', array_merge(array_keys($endpoints), $doubleEndpoints)), json_encode($item['type'], \JSON_THROW_ON_ERROR)));
375499
}
376500
if (
377501
\array_key_exists($item['type'], $endpoints)
@@ -380,36 +504,20 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui
380504
) {
381505
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)));
382506
}
507+
if (\in_array($item['type'], $doubleEndpoints) && !\array_key_exists('code', $item)) {
508+
throw new \InvalidArgumentException(sprintf('The %s type should have a "code" field set.', $item['type']));
509+
}
383510

384511
return $item;
385512
})
386513
->end()
387-
->validate()
388-
->ifArray()
389-
->then(function (array $item) {
390-
if (\in_array($item['type'], self::$doubleEndpoints) && !\array_key_exists('code', $item)) {
391-
throw new \InvalidArgumentException(sprintf('The %s type should have a "code" field set.', $item['type']));
392-
}
393-
394-
return $item;
395-
})
396-
->end()
397514
->children()
398515
->scalarNode('api_type')
399516
->isRequired()
400517
->cannotBeEmpty()
401518
->end()
402519
->scalarNode('type')
403520
->isRequired()
404-
->validate()
405-
->ifNotInArray(array_merge(array_keys(self::$endpoints), self::$doubleEndpoints))
406-
->thenInvalid(
407-
sprintf(
408-
'the value should be one of [%s], got %%s',
409-
implode(', ', array_merge(array_keys(self::$endpoints), self::$doubleEndpoints))
410-
)
411-
)
412-
->end()
413521
->end()
414522
->scalarNode('method')->end()
415523
->scalarNode('code')

src/Configuration/Loader.php

+34-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,39 @@ final class Loader implements Config\Definition\ConfigurationInterface
220220

221221
private static array $endpointsShop = [
222222
// Core Endpoints
223-
223+
'address' => [
224+
'create',
225+
'delete',
226+
'upsert',
227+
],
228+
'customer' => [
229+
'create',
230+
'upsert',
231+
'changePassword',
232+
],
233+
'order' => [
234+
'create',
235+
'upsert',
236+
'choosePayment',
237+
'chooseShipment',
238+
'complete',
239+
],
240+
'orderItem' => [
241+
'create',
242+
'delete',
243+
'changeQuantity',
244+
],
245+
'productReview' => [
246+
'create',
247+
],
248+
'resetPasswordRequest' => [
249+
'create',
250+
'verify',
251+
],
252+
'verifyCustomerAccount' => [
253+
'create',
254+
'verify',
255+
],
224256
];
225257

226258
public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder
@@ -237,7 +269,7 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui
237269
'shop' => self::$endpointsShop,
238270
'legacy' => self::$endpointsLegacy
239271
};
240-
if (!\in_array(array_keys($endpoints), $item['type'])) {
272+
if (!\in_array($item['type'], array_keys($endpoints))) {
241273
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)));
242274
}
243275
if (!\in_array($item['method'], $endpoints[$item['type']])) {

src/Service.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ public function compile(array $config): Factory\Repository\Extractor|Factory\Rep
8989
$extractor = $extractorFactory->compile($config['extractor']);
9090
$extractorBuilder = $extractor->getBuilder();
9191

92-
if (isset($config['extractor']['api_type'])) {
93-
$config['client']['api_type'] = $config['extractor']['api_type'];
94-
}
92+
$config['client']['api_type'] = $config['extractor']['api_type'];
9593
$client = $clientFactory->compile($config['client']);
9694

9795
$extractorBuilder->withClient($client->getBuilder()->getNode());
@@ -107,9 +105,7 @@ public function compile(array $config): Factory\Repository\Extractor|Factory\Rep
107105
$loader = $loaderFactory->compile($config['loader']);
108106
$loaderBuilder = $loader->getBuilder();
109107

110-
if (isset($config['loader']['api_type'])) {
111-
$config['client']['api_type'] = $config['loader']['api_type'];
112-
}
108+
$config['client']['api_type'] = $config['loader']['api_type'];
113109
$client = $clientFactory->compile($config['client']);
114110

115111
$loaderBuilder->withClient($client->getBuilder()->getNode());

0 commit comments

Comments
 (0)