28
28
*/
29
29
class KVClient extends AbstractClient {
30
30
/**
31
- * @param string $key Name of key to retrieve value for
31
+ * @param string $key Name of key to retrieve value for
32
32
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
33
33
* @return array(
34
34
* @type KVPair|null kv object or null on error
@@ -78,7 +78,7 @@ public function get($key, QueryOptions $options = null) {
78
78
}
79
79
80
80
/**
81
- * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
81
+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
82
82
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
83
83
* @return array(
84
84
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -101,7 +101,7 @@ public function put(KVPair $p, WriteOptions $options = null) {
101
101
}
102
102
103
103
/**
104
- * @param string $key
104
+ * @param string $key
105
105
* @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
106
106
* @return array(
107
107
* @type \DCarbone\PHPConsulAPI\WriteMeta metadata about write
@@ -121,7 +121,7 @@ public function delete($key, WriteOptions $options = null) {
121
121
}
122
122
123
123
/**
124
- * @param string $prefix
124
+ * @param string $prefix
125
125
* @param \DCarbone\PHPConsulAPI\QueryOptions|null $options
126
126
* @return array(
127
127
* @type KVPair[]|null array of KVPair objects under specified prefix
@@ -171,7 +171,7 @@ public function valueList($prefix = '', QueryOptions $options = null) {
171
171
}
172
172
173
173
/**
174
- * @param string $prefix Prefix to search for. Null returns all keys.
174
+ * @param string $prefix Prefix to search for. Null returns all keys.
175
175
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
176
176
* @return array(
177
177
* @type string[]|null list of keys
@@ -211,9 +211,10 @@ public function keys($prefix = null, QueryOptions $options = null) {
211
211
}
212
212
213
213
/**
214
- * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
214
+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
215
215
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
216
216
* @return array(
217
+ * @type bool whether the operation succeeded or not
217
218
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
218
219
* @type \DCarbone\PHPConsulAPI\Error|null error, if any
219
220
* )
@@ -225,17 +226,16 @@ public function cas(KVPair $p, WriteOptions $options = null) {
225
226
if (0 !== $ p ->Flags ) {
226
227
$ r ->Params ->set ('flags ' , (string )$ p ->Flags );
227
228
}
228
-
229
- list ($ duration , $ _ , $ err ) = $ this ->requireOK ($ this ->doRequest ($ r ));
229
+ /** @var \Psr\Http\Message\ResponseInterface $response */
230
+ list ($ duration , $ response , $ err ) = $ this ->requireOK ($ this ->doRequest ($ r ));
230
231
if (null !== $ err ) {
231
232
return [null , $ err ];
232
233
}
233
-
234
- return [$ this ->buildWriteMeta ($ duration ), null ];
234
+ return [0 === strpos ($ response ->getBody ()->getContents (), 'true ' ), $ this ->buildWriteMeta ($ duration ), null ];
235
235
}
236
236
237
237
/**
238
- * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
238
+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
239
239
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
240
240
* @return array(
241
241
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -259,7 +259,28 @@ public function acquire(KVPair $p, WriteOptions $options = null) {
259
259
}
260
260
261
261
/**
262
- * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
262
+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
263
+ * @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
264
+ * @return array(
265
+ * @type bool
266
+ * @type \DCarbone\PHPConsulAPI\WriteMeta
267
+ * @type \DCarbone\PHPConsulAPI\Error|null
268
+ * )
269
+ */
270
+ public function deleteCAS (KVPair $ p , WriteOptions $ options = null ) {
271
+ $ r = new Request ('DELETE ' , sprintf ('v1/kv/%s ' , ltrim ($ p ->Key , "/ " )), $ this ->config );
272
+ $ r ->setWriteOptions ($ options );
273
+ $ r ->Params ['cas ' ] = (string )$ p ->ModifyIndex ;
274
+ /** @var \Psr\Http\Message\ResponseInterface $response */
275
+ list ($ duration , $ response , $ err ) = $ this ->requireOK ($ this ->doRequest ($ r ));
276
+ if (null !== $ err ) {
277
+ return [null , null , $ err ];
278
+ }
279
+ return [0 === strpos ($ response ->getBody ()->getContents (), 'true ' ), $ this ->buildWriteMeta ($ duration ), null ];
280
+ }
281
+
282
+ /**
283
+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
263
284
* @param \DCarbone\PHPConsulAPI\WriteOptions $options
264
285
* @return array(
265
286
* @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -283,7 +304,7 @@ public function release(KVPair $p, WriteOptions $options = null) {
283
304
}
284
305
285
306
/**
286
- * @param null|string $prefix
307
+ * @param null|string $prefix
287
308
* @param \DCarbone\PHPConsulAPI\QueryOptions $options
288
309
* @return array(
289
310
* @type KVPair[]|KVTree[]|null array of trees, values, or null on error
0 commit comments