@@ -110,6 +110,7 @@ protected function request(string $requestType, string $uri, array $queryParams
110
110
*
111
111
* @throws LokaliseApiException
112
112
* @throws LokaliseResponseException
113
+ * @deprecated Use requestAllUsingCursor or requestAllUsingPaging instead
113
114
*/
114
115
protected function requestAll (
115
116
string $ requestType ,
@@ -118,12 +119,35 @@ protected function requestAll(
118
119
array $ body = [],
119
120
string $ bodyResponseKey = ''
120
121
): LokaliseApiResponse {
122
+ return $ this ->requestAllUsingPaging ($ requestType , $ uri , $ queryParams , $ body , $ bodyResponseKey );
123
+ }
124
+
125
+ /**
126
+ * @param string $requestType
127
+ * @param string $uri
128
+ * @param array $queryParams
129
+ * @param array $body
130
+ * @param string $bodyResponseKey
131
+ *
132
+ * @return LokaliseApiResponse
133
+ *
134
+ * @throws LokaliseApiException
135
+ * @throws LokaliseResponseException
136
+ */
137
+ protected function requestAllUsingPaging (
138
+ string $ requestType ,
139
+ string $ uri ,
140
+ array $ queryParams = [],
141
+ array $ body = [],
142
+ string $ bodyResponseKey = ''
143
+ ): LokaliseApiResponse
144
+ {
121
145
$ page = 1 ;
122
146
$ queryParams = array_merge ($ queryParams , ['limit ' => static ::FETCH_ALL_LIMIT , 'page ' => $ page ]);
123
147
124
148
$ bodyData = [];
125
149
$ result = $ this ->request ($ requestType , $ uri , $ queryParams , $ body );
126
- if (is_array ($ result ->body [$ bodyResponseKey ])) {
150
+ if (isset ( $ result -> body [ $ bodyResponseKey ]) && is_array ($ result ->body [$ bodyResponseKey ])) {
127
151
$ bodyData = $ result ->body [$ bodyResponseKey ];
128
152
}
129
153
while ($ result ->getPageCount () > $ page ) {
@@ -134,14 +158,59 @@ protected function requestAll(
134
158
135
159
$ result = $ this ->request ($ requestType , $ uri , $ queryParams , $ body );
136
160
if (is_array ($ result ->body [$ bodyResponseKey ])) {
137
- $ bodyData = array_merge ($ result ->body [$ bodyResponseKey ], $ bodyData );
161
+ $ bodyData = array_merge ($ bodyData , $ result ->body [$ bodyResponseKey ]);
138
162
$ result ->body [$ bodyResponseKey ] = $ bodyData ;
139
163
}
140
164
}
141
165
142
166
return $ result ;
143
167
}
144
168
169
+
170
+ /**
171
+ * @param string $requestType
172
+ * @param string $uri
173
+ * @param array $queryParams
174
+ * @param array $body
175
+ * @param string $bodyResponseKey
176
+ *
177
+ * @return LokaliseApiResponse
178
+ *
179
+ * @throws LokaliseApiException
180
+ * @throws LokaliseResponseException
181
+ */
182
+ protected function requestAllUsingCursor (
183
+ string $ requestType ,
184
+ string $ uri ,
185
+ array $ queryParams = [],
186
+ array $ body = [],
187
+ string $ bodyResponseKey = ''
188
+ ): LokaliseApiResponse
189
+ {
190
+ $ bodyData = [];
191
+ $ cursor = '' ;
192
+ $ queryParams ['limit ' ] = static ::FETCH_ALL_LIMIT ;
193
+ $ queryParams ['pagination ' ] = 'cursor ' ;
194
+ while (true ) {
195
+ $ queryParams ['cursor ' ] = $ cursor ;
196
+
197
+ $ result = $ this ->request ($ requestType , $ uri , $ queryParams , $ body );
198
+
199
+ if (is_array ($ result ->body [$ bodyResponseKey ]) && !empty ($ result ->body [$ bodyResponseKey ])) {
200
+ $ bodyData = array_merge ($ bodyData , $ result ->body [$ bodyResponseKey ]);
201
+ $ result ->body [$ bodyResponseKey ] = $ bodyData ;
202
+ }
203
+
204
+ if (!$ result ->hasNextCursor ()) {
205
+ break ;
206
+ }
207
+
208
+ $ cursor = $ result ->getNextCursor ();
209
+ }
210
+
211
+ return $ result ;
212
+ }
213
+
145
214
/**
146
215
* @param array $queryParams
147
216
*
0 commit comments