diff --git a/src/Configuration/Extractor.php b/src/Configuration/Extractor.php index 014d9dc..6a1719b 100644 --- a/src/Configuration/Extractor.php +++ b/src/Configuration/Extractor.php @@ -190,7 +190,7 @@ final class Extractor implements Config\Definition\ConfigurationInterface 'get', 'listPaymentsPerPage', 'allPayments', - 'listShipmentPerPage', + 'listShipmentsPerPage', 'allShipments' ], 'orderItem' => [ @@ -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 = [ @@ -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 @@ -370,8 +494,8 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui $doubleEndpoints = []; break; } - if (!\in_array(array_keys(array_merge($endpoints, $doubleEndpoints)), $item['type'])) { - 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))); + if (!\in_array($item['type'], array_merge(array_keys($endpoints), $doubleEndpoints))) { + 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))); } if ( \array_key_exists($item['type'], $endpoints) @@ -380,20 +504,13 @@ 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() @@ -401,15 +518,6 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui ->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') diff --git a/src/Configuration/Loader.php b/src/Configuration/Loader.php index 2a4c710..3781cda 100644 --- a/src/Configuration/Loader.php +++ b/src/Configuration/Loader.php @@ -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 @@ -237,7 +269,7 @@ public function getConfigTreeBuilder(): \Symfony\Component\Config\Definition\Bui 'shop' => self::$endpointsShop, 'legacy' => self::$endpointsLegacy }; - if (!\in_array(array_keys($endpoints), $item['type'])) { + if (!\in_array($item['type'], array_keys($endpoints))) { 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))); } if (!\in_array($item['method'], $endpoints[$item['type']])) { diff --git a/src/Service.php b/src/Service.php index 3c10e5c..7124f19 100644 --- a/src/Service.php +++ b/src/Service.php @@ -89,9 +89,7 @@ public function compile(array $config): Factory\Repository\Extractor|Factory\Rep $extractor = $extractorFactory->compile($config['extractor']); $extractorBuilder = $extractor->getBuilder(); - if (isset($config['extractor']['api_type'])) { - $config['client']['api_type'] = $config['extractor']['api_type']; - } + $config['client']['api_type'] = $config['extractor']['api_type']; $client = $clientFactory->compile($config['client']); $extractorBuilder->withClient($client->getBuilder()->getNode()); @@ -107,9 +105,7 @@ public function compile(array $config): Factory\Repository\Extractor|Factory\Rep $loader = $loaderFactory->compile($config['loader']); $loaderBuilder = $loader->getBuilder(); - if (isset($config['loader']['api_type'])) { - $config['client']['api_type'] = $config['loader']['api_type']; - } + $config['client']['api_type'] = $config['loader']['api_type']; $client = $clientFactory->compile($config['client']); $loaderBuilder->withClient($client->getBuilder()->getNode());