Skip to content

Commit

Permalink
extract endpoints/methods from ShopApi on extractor/loader class
Browse files Browse the repository at this point in the history
  • Loading branch information
JoMessina committed Oct 26, 2023
1 parent 28283e1 commit 3647cdf
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 21 deletions.
148 changes: 128 additions & 20 deletions src/Configuration/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ final class Extractor implements Config\Definition\ConfigurationInterface
'get',
'listPaymentsPerPage',
'allPayments',
'listShipmentPerPage',
'listShipmentsPerPage',
'allShipments'
],
'orderItem' => [
Expand Down Expand Up @@ -320,6 +320,128 @@ final class Extractor implements Config\Definition\ConfigurationInterface

private static array $endpointsShop = [
// Core Endpoints
'address' => [
'listPerPage',
'all',
'get',
],
'adjustment' => [
'listPerPage',
'all',
'get',
],
'catalogPromotion' => [
'get',
],
'channel' => [
'get',
],
'country' => [
'listPerPage',
'all',
'get',
],
'currency' => [
'listPerPage',
'all',
'get',
],
'customer' => [
'get',
],
'locale' => [
'listPerPage',
'all',
'get',
],
'order' => [
'listPerPage',
'all',
'get',
'listPaymentMethodsPerPage',
'allPaymentMethods',
'listShipmentMethodsPerPage',
'allShipmentMethods',
'listAdjustmentsPerPage',
'allAdjustments',
'listItemsPerPage',
'allItems',
],
'orderItem' => [
'listPerPage',
'all',
'get',
'listAdjustmentsPerPage',
'allAdjustments',
],
'orderItemUnit' => [
'get',
],
'payment' => [
'listPerPage',
'all',
'get',
],
'paymentMethod' => [
'listPerPage',
'all',
'get',
],
'product' => [
'listPerPage',
'all',
'get',
'getBySlug',
],
'productImage' => [
'get',
],
'productOption' => [
'get',
],
'productOptionValue' => [
'get',
],
'productReview' => [
'listPerPage',
'all',
'get',
],
'productTaxon' => [
'get',
],
'productTranslation' => [
'get',
],
'productVariant' => [
'listPerPage',
'all',
'get',
],
'productVariantTranslation' => [
'get',
],
'shipment' => [
'listPerPage',
'all',
'get',
],
'shippingMethod' => [
'listPerPage',
'all',
'get',
],
'shippingMethodTranslation' => [
'get',
],
'taxon' => [
'listPerPage',
'all',
'get',
],
'taxonTranslation' => [
'get',
],
];

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

private static array $doubleEndpointsShop = [
// Double resources Endpoints
'adjustment',
'order',
];

public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder
Expand Down Expand Up @@ -380,36 +504,20 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui
) {
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)));
}
if (\in_array($item['type'], $doubleEndpoints) && !\array_key_exists('code', $item)) {
throw new \InvalidArgumentException(sprintf('The %s type should have a "code" field set.', $item['type']));
}

return $item;
})
->end()
->validate()
->ifArray()
->then(function (array $item) {
if (\in_array($item['type'], self::$doubleEndpoints) && !\array_key_exists('code', $item)) {
throw new \InvalidArgumentException(sprintf('The %s type should have a "code" field set.', $item['type']));
}

return $item;
})
->end()
->children()
->scalarNode('api_type')
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode('type')
->isRequired()
->validate()
->ifNotInArray(array_merge(array_keys(self::$endpoints), self::$doubleEndpoints))
->thenInvalid(
sprintf(
'the value should be one of [%s], got %%s',
implode(', ', array_merge(array_keys(self::$endpoints), self::$doubleEndpoints))
)
)
->end()
->end()
->scalarNode('method')->end()
->scalarNode('code')
Expand Down
34 changes: 33 additions & 1 deletion src/Configuration/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,39 @@ final class Loader implements Config\Definition\ConfigurationInterface

private static array $endpointsShop = [
// Core Endpoints

'address' => [
'create',
'delete',
'upsert',
],
'customer' => [
'create',
'upsert',
'changePassword',
],
'order' => [
'create',
'upsert',
'choosePayment',
'chooseShipment',
'complete',
],
'orderItem' => [
'create',
'delete',
'changeQuantity',
],
'productReview' => [
'create',
],
'resetPasswordRequest' => [
'create',
'verify',
],
'verifyCustomerAccount' => [
'create',
'verify',
],
];

public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Builder\TreeBuilder
Expand Down

0 comments on commit 3647cdf

Please sign in to comment.