Skip to content

Commit bc7fcbf

Browse files
committed
extract endpoints for capacity Create/Upsert/ListPerPage
1 parent 3c3000c commit bc7fcbf

File tree

3 files changed

+164
-8
lines changed

3 files changed

+164
-8
lines changed

src/Capacity/Create.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
final class Create implements CapacityInterface
1212
{
13-
private static array $endpoints = [
13+
private static array $endpointsLegacy = [
1414
// Core Endpoints
1515
'channels',
1616
'countries',
@@ -40,10 +40,51 @@ final class Create implements CapacityInterface
4040
'zones',
4141
];
4242

43+
private static array $endpointsAdmin = [
44+
// Core Endpoints
45+
'administrator',
46+
'avatarImage',
47+
'catalogPromotion',
48+
'channel',
49+
'country',
50+
'currency',
51+
'customerGroup',
52+
'exchangeRate',
53+
'locale',
54+
'product',
55+
'productAssociationType',
56+
'productOption',
57+
'productVariant',
58+
'promotion',
59+
'resetPasswordRequest',
60+
'shippingCategory',
61+
'shippingMethod',
62+
'taxCategory',
63+
'taxon',
64+
'verifyCustomerAccount',
65+
'zone',
66+
];
67+
68+
private static array $endpointsShop = [
69+
// Core Endpoints
70+
'address',
71+
'customer',
72+
'order',
73+
'orderItem',
74+
'productReview',
75+
'resetPasswordRequest',
76+
'verifyCustomerAccount',
77+
];
78+
4379
public function applies(array $config): bool
4480
{
81+
$endpoints = match($config['api_type']) {
82+
'admin' => self::$endpointsAdmin,
83+
'shop' =>self::$endpointsShop,
84+
'legacy' => self::$endpointsLegacy,
85+
};
4586
return isset($config['type'])
46-
&& \in_array($config['type'], self::$endpoints)
87+
&& \in_array($config['type'], $endpoints)
4788
&& isset($config['method'])
4889
&& 'create' === $config['method'];
4990
}

src/Capacity/ListPerPage.php

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
final class ListPerPage implements CapacityInterface
1515
{
16-
private static array $endpoints = [
16+
private static array $endpointsLegacy = [
1717
// Simple resources Endpoints
1818
'channels',
1919
'countries',
@@ -41,26 +41,110 @@ final class ListPerPage implements CapacityInterface
4141
'zones',
4242
];
4343

44-
private static array $doubleEndpoints = [
44+
private static array $endpointsAdmin = [
45+
// Simple Ressource Endpoints
46+
'adjustment',
47+
'administrator',
48+
'catalogPromotion',
49+
'channel',
50+
'country',
51+
'currency',
52+
'customerGroup',
53+
'exchangeRate',
54+
'locale',
55+
'order',
56+
'payment',
57+
'product',
58+
'productAssociationType',
59+
'productImage',
60+
'productOption',
61+
'productOptionValue',
62+
'productReview',
63+
'productTaxon',
64+
'productVariant',
65+
'promotion',
66+
'province',
67+
'shipment',
68+
'shippingCategory',
69+
'shippingMethod',
70+
'ShopBillingData',
71+
'taxCategory',
72+
'taxon',
73+
'taxonTranslation',
74+
'zone',
75+
'zoneMember',
76+
];
77+
78+
private static array $endpointsShop = [
79+
// Simple Ressource Endpoints
80+
'address',
81+
'adjustment',
82+
'country',
83+
'currency',
84+
'locale',
85+
'order',
86+
'orderItem',
87+
'payment',
88+
'paymentMethod',
89+
'product',
90+
'productReview',
91+
'productVariant',
92+
'shipment',
93+
'shippingMethod',
94+
'taxon',
95+
];
96+
97+
private static array $doubleEndpointsLegacy = [
4598
// Double resources Endpoints
4699
'productReviews',
47100
'productVariants',
48101
'promotionCoupons',
49102
];
103+
private static array $doubleEndpointsAdmin = [
104+
// Double resources Endpoints
105+
'adjustment',
106+
'province',
107+
'shopBillingData',
108+
'zoneMember',
109+
];
110+
111+
private static array $doubleEndpointsShop = [
112+
// Double resources Endpoints
113+
'adjustment',
114+
'order',
115+
];
50116

51117
public function __construct(private readonly ExpressionLanguage $interpreter)
52118
{
53119
}
54120

55121
public function applies(array $config): bool
56122
{
123+
switch($config['api_type']) {
124+
case 'admin':
125+
$endpoints = self::$endpointsAdmin;
126+
$doubleEndpoints = self::$doubleEndpointsAdmin;
127+
break;
128+
case 'shop':
129+
$endpoints = self::$endpointsShop;
130+
$doubleEndpoints = self::$doubleEndpointsShop;
131+
break;
132+
case 'legacy':
133+
$endpoints = self::$endpointsLegacy;
134+
$doubleEndpoints = self::$doubleEndpointsLegacy;
135+
break;
136+
default:
137+
$endpoints = [];
138+
$doubleEndpoints = [];
139+
break;
140+
}
57141
return isset($config['type'])
58-
&& (\in_array($config['type'], self::$endpoints) || \in_array($config['type'], self::$doubleEndpoints))
142+
&& (\in_array($config['type'], $endpoints) || \in_array($config['type'], $doubleEndpoints))
59143
&& isset($config['method'])
60144
&& 'listPerPage' === $config['method'];
61145
}
62146

63-
private function compileFilters(array ...$filters): Node
147+
private function compileFilters(array ...$filters): Node\Expr
64148
{
65149
$builder = new Sylius\Builder\Search();
66150
foreach ($filters as $filter) {

src/Capacity/Upsert.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
final class Upsert implements CapacityInterface
1212
{
13-
private static array $endpoints = [
13+
private static array $endpointsLegacy = [
1414
// Core Endpoints
1515
'carts',
1616
'channels',
@@ -42,10 +42,41 @@ final class Upsert implements CapacityInterface
4242
'zones',
4343
];
4444

45+
private static array $endpointsAdmin = [
46+
// Core Endpoints
47+
'administrator',
48+
'catalogPromotion',
49+
'customerGroup',
50+
'exchangeRate',
51+
'product',
52+
'productAssociationType',
53+
'productOption',
54+
'productReview',
55+
'productVariant',
56+
'province',
57+
'shippingCategory',
58+
'shippingMethod',
59+
'taxCategory',
60+
'taxon',
61+
'zone',
62+
];
63+
64+
private static array $endpointsShop = [
65+
// Core Endpoints
66+
'address',
67+
'customer',
68+
'order',
69+
];
70+
4571
public function applies(array $config): bool
4672
{
73+
$endpoints = match($config['api_type']) {
74+
'admin' => self::$endpointsAdmin,
75+
'shop' =>self::$endpointsShop,
76+
'legacy' => self::$endpointsLegacy,
77+
};
4778
return isset($config['type'])
48-
&& \in_array($config['type'], self::$endpoints)
79+
&& \in_array($config['type'], $endpoints)
4980
&& isset($config['method'])
5081
&& 'upsert' === $config['method'];
5182
}

0 commit comments

Comments
 (0)