@@ -48,7 +48,7 @@ public function __construct(
48
48
*/
49
49
public static function create ($ appId = null , $ apiKey = null , $ region = null )
50
50
{
51
- $ allowedRegions = [ ' de ' , ' us ' ] ;
51
+ $ allowedRegions = self :: getAllowedRegions () ;
52
52
$ config = AbtestingConfig::create (
53
53
$ appId ,
54
54
$ apiKey ,
@@ -59,6 +59,14 @@ public static function create($appId = null, $apiKey = null, $region = null)
59
59
return static ::createWithConfig ($ config );
60
60
}
61
61
62
+ /**
63
+ * Returns the allowed regions for the config
64
+ */
65
+ public static function getAllowedRegions ()
66
+ {
67
+ return ['de ' , 'us ' ];
68
+ }
69
+
62
70
/**
63
71
* Instantiate the client with configuration
64
72
*
@@ -68,25 +76,40 @@ public static function createWithConfig(AbtestingConfig $config)
68
76
{
69
77
$ config = clone $ config ;
70
78
79
+ $ apiWrapper = new ApiWrapper (
80
+ Algolia::getHttpClient (),
81
+ $ config ,
82
+ self ::getClusterHosts ($ config )
83
+ );
84
+
85
+ return new static ($ apiWrapper , $ config );
86
+ }
87
+
88
+ /**
89
+ * Gets the cluster hosts depending on the config
90
+ *
91
+ * @param AbtestingConfig $config
92
+ *
93
+ * @return ClusterHosts
94
+ */
95
+ public static function getClusterHosts (AbtestingConfig $ config )
96
+ {
71
97
if ($ hosts = $ config ->getHosts ()) {
72
98
// If a list of hosts was passed, we ignore the cache
73
99
$ clusterHosts = ClusterHosts::create ($ hosts );
74
100
} else {
75
- $ url = str_replace (
76
- '{region} ' ,
77
- $ config ->getRegion (),
78
- 'analytics.{region}.algolia.com '
79
- );
101
+ $ url =
102
+ $ config ->getRegion () !== null && $ config ->getRegion () !== ''
103
+ ? str_replace (
104
+ '{region} ' ,
105
+ $ config ->getRegion (),
106
+ 'analytics.{region}.algolia.com '
107
+ )
108
+ : 'analytics.algolia.com ' ;
80
109
$ clusterHosts = ClusterHosts::create ($ url );
81
110
}
82
111
83
- $ apiWrapper = new ApiWrapper (
84
- Algolia::getHttpClient (),
85
- $ config ,
86
- $ clusterHosts
87
- );
88
-
89
- return new static ($ apiWrapper , $ config );
112
+ return $ clusterHosts ;
90
113
}
91
114
92
115
/**
@@ -114,12 +137,9 @@ public function getClientConfig()
114
137
public function addABTests ($ addABTestsRequest , $ requestOptions = [])
115
138
{
116
139
// verify the required parameter 'addABTestsRequest' is set
117
- if (
118
- $ addABTestsRequest === null ||
119
- (is_array ($ addABTestsRequest ) && count ($ addABTestsRequest ) === 0 )
120
- ) {
140
+ if ($ addABTestsRequest === null ) {
121
141
throw new \InvalidArgumentException (
122
- 'Missing the required parameter $addABTestsRequest when calling addABTests '
142
+ 'Parameter `addABTestsRequest` is required when calling ` addABTests`. '
123
143
);
124
144
}
125
145
@@ -154,9 +174,9 @@ public function addABTests($addABTestsRequest, $requestOptions = [])
154
174
public function del ($ path , $ parameters = null , $ requestOptions = [])
155
175
{
156
176
// verify the required parameter 'path' is set
157
- if ($ path === null || ( is_array ( $ path ) && count ( $ path ) === 0 ) ) {
177
+ if ($ path === null ) {
158
178
throw new \InvalidArgumentException (
159
- 'Missing the required parameter $path when calling del '
179
+ 'Parameter `path` is required when calling ` del`. '
160
180
);
161
181
}
162
182
@@ -195,9 +215,9 @@ public function del($path, $parameters = null, $requestOptions = [])
195
215
public function deleteABTest ($ id , $ requestOptions = [])
196
216
{
197
217
// verify the required parameter 'id' is set
198
- if ($ id === null || ( is_array ( $ id ) && count ( $ id ) === 0 ) ) {
218
+ if ($ id === null ) {
199
219
throw new \InvalidArgumentException (
200
- 'Missing the required parameter $id when calling deleteABTest '
220
+ 'Parameter `id` is required when calling ` deleteABTest`. '
201
221
);
202
222
}
203
223
@@ -237,9 +257,9 @@ public function deleteABTest($id, $requestOptions = [])
237
257
public function get ($ path , $ parameters = null , $ requestOptions = [])
238
258
{
239
259
// verify the required parameter 'path' is set
240
- if ($ path === null || ( is_array ( $ path ) && count ( $ path ) === 0 ) ) {
260
+ if ($ path === null ) {
241
261
throw new \InvalidArgumentException (
242
- 'Missing the required parameter $path when calling get '
262
+ 'Parameter `path` is required when calling ` get`. '
243
263
);
244
264
}
245
265
@@ -278,9 +298,9 @@ public function get($path, $parameters = null, $requestOptions = [])
278
298
public function getABTest ($ id , $ requestOptions = [])
279
299
{
280
300
// verify the required parameter 'id' is set
281
- if ($ id === null || ( is_array ( $ id ) && count ( $ id ) === 0 ) ) {
301
+ if ($ id === null ) {
282
302
throw new \InvalidArgumentException (
283
- 'Missing the required parameter $id when calling getABTest '
303
+ 'Parameter `id` is required when calling ` getABTest`. '
284
304
);
285
305
}
286
306
@@ -362,9 +382,9 @@ public function post(
362
382
$ requestOptions = []
363
383
) {
364
384
// verify the required parameter 'path' is set
365
- if ($ path === null || ( is_array ( $ path ) && count ( $ path ) === 0 ) ) {
385
+ if ($ path === null ) {
366
386
throw new \InvalidArgumentException (
367
- 'Missing the required parameter $path when calling post '
387
+ 'Parameter `path` is required when calling ` post`. '
368
388
);
369
389
}
370
390
@@ -413,9 +433,9 @@ public function put(
413
433
$ requestOptions = []
414
434
) {
415
435
// verify the required parameter 'path' is set
416
- if ($ path === null || ( is_array ( $ path ) && count ( $ path ) === 0 ) ) {
436
+ if ($ path === null ) {
417
437
throw new \InvalidArgumentException (
418
- 'Missing the required parameter $path when calling put '
438
+ 'Parameter `path` is required when calling ` put`. '
419
439
);
420
440
}
421
441
@@ -458,9 +478,9 @@ public function put(
458
478
public function stopABTest ($ id , $ requestOptions = [])
459
479
{
460
480
// verify the required parameter 'id' is set
461
- if ($ id === null || ( is_array ( $ id ) && count ( $ id ) === 0 ) ) {
481
+ if ($ id === null ) {
462
482
throw new \InvalidArgumentException (
463
- 'Missing the required parameter $id when calling stopABTest '
483
+ 'Parameter `id` is required when calling ` stopABTest`. '
464
484
);
465
485
}
466
486
0 commit comments