WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit a285bdf

Browse files
authored
Mark Bookmark Methods as Deprecated (From Discussions #209)
2 parents be7a513 + 263d801 commit a285bdf

File tree

5 files changed

+208
-2
lines changed

5 files changed

+208
-2
lines changed

src/Prismic/Api.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public function getRefFromLabel(string $label) :? Ref
151151
* Returns the list of all bookmarks on the repository. If you're looking
152152
* for a document from it's bookmark name, you should use the bookmark() function.
153153
*
154+
* @deprecated 5.4.0 This method will no longer work after the 12 February 2025,
155+
* as bookmarks are removed from the API.
156+
*
154157
* @return array the array of bookmarks
155158
*/
156159
public function bookmarks() : array
@@ -165,6 +168,9 @@ public function bookmarks() : array
165168
* Most starter projects embed a helper to query a document from their ID string,
166169
* which makes this even easier.
167170
*
171+
* @deprecated 5.4.0 This method will no longer work after the 12 February 2025,
172+
* as bookmarks are removed from the API.
173+
*
168174
* @param string $name the bookmark name to use
169175
*
170176
* @return string|null the ID string for a given bookmark name

src/Prismic/ApiData.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class ApiData
1616

1717
/**
1818
* An array of the available bookmarks
19+
*
20+
* @deprecated 5.4.0
21+
*
1922
* @var array
2023
*/
2124
private $bookmarks;
@@ -66,7 +69,7 @@ class ApiData
6669
* A constructor to build the object when you've retrieved all the data you need.
6770
*
6871
* @param array $refs
69-
* @param array $bookmarks
72+
* @param array $bookmarks (deprecated since 5.4.0)
7073
* @param array $types
7174
* @param array $languages
7275
* @param array $tags
@@ -131,7 +134,7 @@ function ($ref) {
131134
},
132135
$json->refs
133136
),
134-
(array)$json->bookmarks,
137+
isset($json->bookmarks) ? (array)$json->bookmarks : [],
135138
(array)$json->types,
136139
array_map(
137140
function ($language) {
@@ -158,6 +161,9 @@ public function getRefs() : array
158161

159162
/**
160163
* Get the bookmarks
164+
*
165+
* @deprecated 5.4.0 This method will no longer work after the 12 February 2025,
166+
* as bookmarks are removed from the API.
161167
*/
162168
public function getBookmarks() : array
163169
{

tests/Prismic/ApiDataTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public function testWithJsonStringThrowsExceptionForInvalidJson()
3636
ApiData::withJsonString('wtf?');
3737
}
3838

39+
public function testApiDataWorksWithoutBookmarks()
40+
{
41+
$json = $this->getJsonFixture('data-without-bookmarks.json');
42+
$data = ApiData::withJsonString($json);
43+
44+
$this->assertInstanceOf(ApiData::class, $data);
45+
$this->assertEquals([], $data->getBookmarks());
46+
}
47+
3948
public function testApiDataHasExpectedValues()
4049
{
4150
$this->assertCount(3, $this->data->getRefs());

tests/Prismic/ApiTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,26 @@ public function testBookmarkReturnsCorrectDocumentId()
201201
$this->assertNull($api->bookmark('unknown-bookmark'));
202202
}
203203

204+
public function testApiWorksWithoutBookmarks()
205+
{
206+
// Create an ApiData object without bookmarks
207+
$data = $this->getJsonFixture('data-without-bookmarks.json');
208+
$apiData = ApiData::withJsonString($data);
209+
210+
// Cache the data
211+
$key = 'https://whatever.prismic.io/api/v2#My-Access-Token';
212+
$cachedData = serialize($apiData);
213+
$this->cache->get($key)->willReturn($cachedData);
214+
$this->httpClient->request()->shouldNotBeCalled();
215+
216+
$api = $this->getApi();
217+
218+
// Test that the bookmarks are empty
219+
$this->assertEmpty($api->bookmarks());
220+
$this->assertNull($api->bookmark('about'));
221+
$this->assertNull($api->bookmark('unknown-bookmark'));
222+
}
223+
204224
public function testFormsReturnsOnlyFormInstances()
205225
{
206226
$api = $this->getApiWithDefaultData();
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"refs": [
3+
{
4+
"id": "master",
5+
"ref": "UgjWQN_mqa8HvPJY",
6+
"label": "Master",
7+
"isMasterRef": true
8+
},
9+
{
10+
"id": "UkL0hcuvzYUANCrr",
11+
"ref": "UgjWRd_mqbYHvPJa",
12+
"label": "San Francisco Grand opening"
13+
},
14+
{
15+
"id": "SaGrandOpening2ndRef",
16+
"ref": "SaGrandOpening2ndRef",
17+
"label": "San Francisco Grand opening"
18+
}
19+
],
20+
"types": {
21+
"blog-post": "Blog post",
22+
"store": "Store",
23+
"article": "Site-level article",
24+
"selection": "Products selection",
25+
"job-offer": "Job offer",
26+
"product": "Product"
27+
},
28+
"languages": [
29+
{
30+
"id": "en-us",
31+
"name": "English - United States"
32+
},
33+
{
34+
"id": "nl-nl",
35+
"name": "Dutch - Netherlands"
36+
},
37+
{
38+
"id": "es-es",
39+
"name": "Spanish - Spain (Traditional)"
40+
},
41+
{
42+
"id": "fr-fr",
43+
"name": "French - France"
44+
}
45+
],
46+
"tags": ["Cupcake", "Pie", "Featured", "Macaron"],
47+
"forms": {
48+
"everything": {
49+
"method": "GET",
50+
"enctype": "application/x-www-form-urlencoded",
51+
"action": "http://lesbonneschoses.prismic.io/api/v2/documents/search",
52+
"fields": {
53+
"ref": {
54+
"type": "String"
55+
},
56+
"q": {
57+
"type": "String"
58+
}
59+
}
60+
},
61+
"blogs": {
62+
"name": "Blog Posts",
63+
"method": "GET",
64+
"rel": "collection",
65+
"enctype": "application/x-www-form-urlencoded",
66+
"action": "https://lesbonneschoses.prismic.io/api/v2/documents/search",
67+
"fields": {
68+
"ref": {
69+
"type": "String",
70+
"multiple": false
71+
},
72+
"q": {
73+
"default": "[[:d = any(document.type, [\"blog-post\"])]]",
74+
"type": "String",
75+
"multiple": true
76+
},
77+
"lang": {
78+
"type": "String",
79+
"multiple": false
80+
},
81+
"page": {
82+
"type": "Integer",
83+
"multiple": false,
84+
"default": "1"
85+
},
86+
"pageSize": {
87+
"type": "Integer",
88+
"multiple": false,
89+
"default": "20"
90+
},
91+
"after": {
92+
"type": "String",
93+
"multiple": false
94+
},
95+
"fetch": {
96+
"type": "String",
97+
"multiple": false
98+
},
99+
"fetchLinks": {
100+
"type": "String",
101+
"multiple": false
102+
},
103+
"graphQuery": {
104+
"type": "String",
105+
"multiple": false
106+
},
107+
"orderings": {
108+
"type": "String",
109+
"multiple": false
110+
},
111+
"referer": {
112+
"type": "String",
113+
"multiple": false
114+
},
115+
"access_token": {
116+
"default": "a-permanent-access-token",
117+
"type": "String",
118+
"multiple": false
119+
}
120+
}
121+
}
122+
},
123+
"oauth_initiate": "http://lesbonneschoses.prismic.io/auth",
124+
"oauth_token": "http://lesbonneschoses.prismic.io/auth/token",
125+
"experiments" : {
126+
"draft": [
127+
{
128+
"id": "xxxxxxxxxxoGelsX",
129+
"name": "Exp 2",
130+
"variations": [
131+
{
132+
"id": "VDUBBawGAKoGelsZ",
133+
"label": "Base",
134+
"ref": "VDUBBawGALAGelsa"
135+
},
136+
{
137+
"id": "VDUE-awGALAGemME",
138+
"label": "var 1",
139+
"ref": "VDUUmHIKAZQKk9uq"
140+
}
141+
]
142+
}
143+
],
144+
"running": [
145+
{
146+
"googleId": "_UQtin7EQAOH5M34RQq6Dg",
147+
"id": "VDUBBawGAKoGelsX",
148+
"name": "Exp 1",
149+
"variations": [
150+
{
151+
"id": "VDUBBawGAKoGelsZ",
152+
"label": "Base",
153+
"ref": "VDUBBawGALAGelsa"
154+
},
155+
{
156+
"id": "VDUE-awGALAGemME",
157+
"label": "var 1",
158+
"ref": "VDUUmHIKAZQKk9uq"
159+
}
160+
]
161+
}
162+
]
163+
}
164+
165+
}

0 commit comments

Comments
 (0)