4
4
5
5
namespace Kiboko \Plugin \Sylius \Capacity ;
6
6
7
- use Kiboko \Contract \Configurator \InvalidConfigurationException ;
8
7
use Kiboko \Plugin \Sylius ;
9
- use Kiboko \Plugin \Sylius \Validator \ApiType ;
10
8
use PhpParser \Builder ;
11
9
use PhpParser \Node ;
12
10
use Symfony \Component \ExpressionLanguage \ExpressionLanguage ;
13
11
14
- use function Kiboko \Component \SatelliteToolbox \Configuration \compileValue ;
12
+ use function Kiboko \Component \SatelliteToolbox \Configuration \compileValueWhenExpression ;
15
13
16
14
final class All implements CapacityInterface
17
15
{
18
- private static array $ endpointsLegacy = [
19
- // Simple resources Endpoints
20
- 'channels ' ,
21
- 'countries ' ,
22
- 'carts ' ,
23
- 'channels ' ,
24
- 'countries ' ,
25
- 'currencies ' ,
26
- 'customers ' ,
27
- 'exchangeRates ' ,
28
- 'locales ' ,
29
- 'orders ' ,
30
- 'payments ' ,
31
- 'paymentMethods ' ,
32
- 'products ' ,
33
- 'productAttributes ' ,
34
- 'productAssociationTypes ' ,
35
- 'productOptions ' ,
36
- 'promotions ' ,
37
- 'shipments ' ,
38
- 'shippingCategories ' ,
39
- 'taxCategories ' ,
40
- 'taxRates ' ,
41
- 'taxons ' ,
42
- 'users ' ,
43
- 'zones ' ,
44
- ];
45
-
46
- private static array $ endpointsAdmin = [
47
- // Simple Ressource Endpoints
48
- 'adjustment ' ,
49
- 'administrator ' ,
50
- 'catalogPromotion ' ,
51
- 'channel ' ,
52
- 'country ' ,
53
- 'currency ' ,
54
- 'customerGroup ' ,
55
- 'exchangeRate ' ,
56
- 'locale ' ,
57
- 'order ' ,
58
- 'payment ' ,
59
- 'product ' ,
60
- 'productAssociationType ' ,
61
- 'productImage ' ,
62
- 'productOption ' ,
63
- 'productOptionValue ' ,
64
- 'productReview ' ,
65
- 'productTaxon ' ,
66
- 'productVariant ' ,
67
- 'promotion ' ,
68
- 'province ' ,
69
- 'shipment ' ,
70
- 'shippingCategory ' ,
71
- 'shippingMethod ' ,
72
- 'ShopBillingData ' ,
73
- 'taxCategory ' ,
74
- 'taxon ' ,
75
- 'taxonTranslation ' ,
76
- 'zone ' ,
77
- 'zoneMember ' ,
78
- ];
79
-
80
- private static array $ endpointsShop = [
81
- // Simple Ressource Endpoints
82
- 'address ' ,
83
- 'adjustment ' ,
84
- 'country ' ,
85
- 'currency ' ,
86
- 'locale ' ,
87
- 'order ' ,
88
- 'orderItem ' ,
89
- 'payment ' ,
90
- 'paymentMethod ' ,
91
- 'product ' ,
92
- 'productReview ' ,
93
- 'productVariant ' ,
94
- 'shipment ' ,
95
- 'shippingMethod ' ,
96
- 'taxon ' ,
97
- ];
98
-
99
- private static array $ doubleEndpointsLegacy = [
100
- // Double resources Endpoints
101
- 'productReviews ' ,
102
- 'productVariants ' ,
103
- 'promotionCoupons ' ,
104
- ];
105
-
106
- private static array $ doubleEndpointsAdmin = [
107
- // Double resources Endpoints
108
- 'adjustment ' ,
109
- 'province ' ,
110
- 'shopBillingData ' ,
111
- 'zoneMember ' ,
112
- ];
113
-
114
- private static array $ doubleEndpointsShop = [
115
- // Double resources Endpoints
116
- 'adjustment ' ,
117
- 'order ' ,
118
- ];
119
-
120
16
public function __construct (private readonly ExpressionLanguage $ interpreter ) {}
121
17
122
18
public function applies (array $ config ): bool
123
19
{
124
- if (!isset ($ config ['api_type ' ])) {
125
- throw new InvalidConfigurationException ('Your Sylius API configuration is using some unsupported capacity, check your "api_type" properties to a suitable set. ' );
126
- }
127
- switch ($ config ['api_type ' ]) {
128
- case 'admin ' :
129
- $ endpoints = self ::$ endpointsAdmin ;
130
- $ doubleEndpoints = self ::$ doubleEndpointsAdmin ;
131
- break ;
132
- case 'shop ' :
133
- $ endpoints = self ::$ endpointsShop ;
134
- $ doubleEndpoints = self ::$ doubleEndpointsShop ;
135
- break ;
136
- case 'legacy ' :
137
- $ endpoints = self ::$ endpointsLegacy ;
138
- $ doubleEndpoints = self ::$ doubleEndpointsLegacy ;
139
- break ;
140
- default :
141
- throw new \InvalidArgumentException (sprintf ('The value of api_type should be one of [%s], got %s. ' , implode (', ' , ApiType::casesValue ()), json_encode ($ config ['api_type ' ], \JSON_THROW_ON_ERROR )));
142
- }
20
+ $ endpoints = array_merge (
21
+ Sylius \Validator \ExtractorConfigurationValidator::ADMIN_VALID_TYPES ,
22
+ Sylius \Validator \ExtractorConfigurationValidator::SHOP_VALID_TYPES ,
23
+ );
143
24
144
25
return isset ($ config ['type ' ])
145
- && ( \in_array ($ config ['type ' ], $ endpoints) || \in_array ( $ config [ ' type ' ], $ doubleEndpoints ) )
26
+ && \array_key_exists ($ config ['type ' ], $ endpoints )
146
27
&& isset ($ config ['method ' ])
147
28
&& 'all ' === $ config ['method ' ];
148
29
}
@@ -152,11 +33,11 @@ private function compileFilters(array ...$filters): Node\Expr
152
33
$ builder = new Sylius \Builder \Search ();
153
34
foreach ($ filters as $ filter ) {
154
35
$ builder ->addFilter (
155
- field: compileValue ($ this ->interpreter , $ filter ['field ' ]),
156
- operator: compileValue ($ this ->interpreter , $ filter ['operator ' ]),
157
- value: compileValue ($ this ->interpreter , $ filter ['value ' ]),
158
- scope: \array_key_exists ('scope ' , $ filter ) ? compileValue ($ this ->interpreter , $ filter ['scope ' ]) : null ,
159
- locale: \array_key_exists ('locale ' , $ filter ) ? compileValue ($ this ->interpreter , $ filter ['locale ' ]) : null
36
+ field: compileValueWhenExpression ($ this ->interpreter , $ filter ['field ' ]),
37
+ operator: compileValueWhenExpression ($ this ->interpreter , $ filter ['operator ' ]),
38
+ value: compileValueWhenExpression ($ this ->interpreter , $ filter ['value ' ]),
39
+ scope: \array_key_exists ('scope ' , $ filter ) ? compileValueWhenExpression ($ this ->interpreter , $ filter ['scope ' ]) : null ,
40
+ locale: \array_key_exists ('locale ' , $ filter ) ? compileValueWhenExpression ($ this ->interpreter , $ filter ['locale ' ]) : null
160
41
);
161
42
}
162
43
0 commit comments