15
15
use Markup \Contentful \Exception \ResourceUnavailableException ;
16
16
use Markup \Contentful \Filter \ContentTypeFilterProvider ;
17
17
use Markup \Contentful \Filter \DecidesCacheKeyInterface ;
18
+ use Markup \Contentful \Filter \LocaleFilter ;
18
19
use Markup \Contentful \Log \LoggerInterface ;
19
20
use Markup \Contentful \Log \LogInterface ;
20
21
use Markup \Contentful \Log \NullLogger ;
@@ -147,15 +148,16 @@ public function getSpaceAsync($space = null, array $options = [])
147
148
* @param string $id
148
149
* @param string|SpaceInterface $space
149
150
* @param array $options A set of options for the fetch, including 'include_level' being how many levels to include
151
+ * @param string $locale A locale for the entry data, if one is specified (otherwise, API will use default locale for the space)
150
152
* @return EntryInterface|PromiseInterface
151
153
* @throws Exception\ResourceUnavailableException
152
154
*/
153
- public function getEntry ($ id , $ space = null , array $ options = [])
155
+ public function getEntry ($ id , $ space = null , array $ options = [], $ locale = null )
154
156
{
155
- if ($ this ->envelope ->hasEntry ($ id )) {
157
+ if ($ this ->envelope ->hasEntry ($ id, $ locale )) {
156
158
return ($ this ->isAsyncCall ($ options ))
157
- ? promise_for ($ this ->envelope ->findEntry ($ id ))
158
- : $ this ->envelope ->findEntry ($ id );
159
+ ? promise_for ($ this ->envelope ->findEntry ($ id, $ locale ))
160
+ : $ this ->envelope ->findEntry ($ id, $ locale );
159
161
}
160
162
$ spaceName = ($ space instanceof SpaceInterface) ? $ space ->getName () : $ space ;
161
163
$ spaceData = $ this ->getSpaceDataForName (($ space instanceof SpaceInterface) ? $ space ->getName () : $ space );
@@ -169,7 +171,7 @@ public function getEntry($id, $space = null, array $options = [])
169
171
$ api ,
170
172
'entry ' ,
171
173
strval ($ id ),
172
- [],
174
+ ( $ locale ) ? [ new LocaleFilter ( $ locale )] : [],
173
175
$ options
174
176
);
175
177
}
@@ -178,12 +180,13 @@ public function getEntry($id, $space = null, array $options = [])
178
180
* @param string $id
179
181
* @param string|SpaceInterface $space
180
182
* @param array $options
183
+ * @param string|null $locale
181
184
* @return EntryInterface|PromiseInterface
182
185
*/
183
- public function getEntryAsync ($ id , $ space = null , array $ options = [])
186
+ public function getEntryAsync ($ id , $ space = null , array $ options = [], $ locale = null )
184
187
{
185
188
return new EntryPromise (
186
- $ this ->getEntry ($ id , $ space , array_merge ($ options , ['async ' => true ]))
189
+ $ this ->getEntry ($ id , $ space , array_merge ($ options , ['async ' => true ]), $ locale )
187
190
);
188
191
}
189
192
@@ -230,14 +233,15 @@ public function getEntriesAsync(array $parameters = [], $space = null, array $op
230
233
* @param string $id
231
234
* @param string|SpaceInterface $space
232
235
* @param array $options
236
+ * @param string|null $locale
233
237
* @return AssetInterface|PromiseInterface
234
238
*/
235
- public function getAsset ($ id , $ space = null , array $ options = [])
239
+ public function getAsset ($ id , $ space = null , array $ options = [], $ locale = null )
236
240
{
237
- if ($ this ->envelope ->hasAsset ($ id )) {
241
+ if ($ this ->envelope ->hasAsset ($ id, $ locale )) {
238
242
return ($ this ->isAsyncCall ($ options ))
239
- ? promise_for ($ this ->envelope ->findAsset ($ id ))
240
- : $ this ->envelope ->findAsset ($ id );
243
+ ? promise_for ($ this ->envelope ->findAsset ($ id, $ locale ))
244
+ : $ this ->envelope ->findAsset ($ id, $ locale );
241
245
}
242
246
$ spaceName = ($ space instanceof SpaceInterface) ? $ space ->getName () : $ space ;
243
247
$ spaceData = $ this ->getSpaceDataForName ($ spaceName );
@@ -251,7 +255,7 @@ public function getAsset($id, $space = null, array $options = [])
251
255
$ api ,
252
256
'asset ' ,
253
257
strval ($ id ),
254
- [],
258
+ ( $ locale ) ? [ new LocaleFilter ( $ locale )] : [],
255
259
$ options
256
260
);
257
261
}
@@ -260,12 +264,13 @@ public function getAsset($id, $space = null, array $options = [])
260
264
* @param string $id
261
265
* @param string|SpaceInterface $space
262
266
* @param array $options
267
+ * @param string|null $locale
263
268
* @return AssetInterface|PromiseInterface
264
269
*/
265
- public function getAssetAsync ($ id , $ space = null , array $ options = [])
270
+ public function getAssetAsync ($ id , $ space = null , array $ options = [], $ locale = null )
266
271
{
267
272
return new AssetPromise (
268
- $ this ->getAsset ($ id , $ space , array_merge ($ options , ['async ' => true ]))
273
+ $ this ->getAsset ($ id , $ space , array_merge ($ options , ['async ' => true ]), $ locale )
269
274
);
270
275
}
271
276
@@ -406,11 +411,12 @@ public function getContentTypeByNameAsync($name, $space = null, array $options =
406
411
}
407
412
408
413
/**
409
- * @param Link $link
410
- * @param array $options
414
+ * @param Link $link
415
+ * @param array $options
416
+ * @param string|null $locale
411
417
* @return PromiseInterface
412
418
*/
413
- public function resolveLink ($ link , array $ options = [])
419
+ public function resolveLink ($ link , array $ options = [], $ locale = null )
414
420
{
415
421
//check whether the "link" is already actually a resolved resource
416
422
if ($ link instanceof ResourceInterface) {
@@ -422,13 +428,15 @@ public function resolveLink($link, array $options = [])
422
428
return $ this ->getEntry (
423
429
$ link ->getId (),
424
430
$ link ->getSpaceName (),
425
- array_merge ($ options , ['async ' => true ])
431
+ array_merge ($ options , ['async ' => true ]),
432
+ $ locale
426
433
);
427
434
case 'Asset ' :
428
435
return $ this ->getAsset (
429
436
$ link ->getId (),
430
437
$ link ->getSpaceName (),
431
- array_merge ($ options , ['async ' => true ])
438
+ array_merge ($ options , ['async ' => true ]),
439
+ $ locale
432
440
);
433
441
case 'ContentType ' :
434
442
return $ this ->getContentType (
@@ -876,8 +884,8 @@ private function buildResponseFromRaw(
876
884
static $ resourceBuilder ;
877
885
if (empty ($ resourceBuilder )) {
878
886
$ resourceBuilder = new ResourceBuilder ($ this ->envelope );
879
- $ resourceBuilder ->setResolveLinkFunction (function ($ link ) {
880
- return $ this ->resolveLink ($ link );
887
+ $ resourceBuilder ->setResolveLinkFunction (function ($ link, $ locale = null ) {
888
+ return $ this ->resolveLink ($ link, [], $ locale );
881
889
});
882
890
}
883
891
$ resourceBuilder ->setUseDynamicEntries ($ useTypedResources );
0 commit comments