2828 */
2929class KVClient extends AbstractClient {
3030 /**
31- * @param string $key Name of key to retrieve value for
31+ * @param string $key Name of key to retrieve value for
3232 * @param \DCarbone\PHPConsulAPI\QueryOptions $options
3333 * @return array(
3434 * @type KVPair|null kv object or null on error
@@ -78,7 +78,7 @@ public function get($key, QueryOptions $options = null) {
7878 }
7979
8080 /**
81- * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
81+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
8282 * @param \DCarbone\PHPConsulAPI\WriteOptions $options
8383 * @return array(
8484 * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -101,7 +101,7 @@ public function put(KVPair $p, WriteOptions $options = null) {
101101 }
102102
103103 /**
104- * @param string $key
104+ * @param string $key
105105 * @param \DCarbone\PHPConsulAPI\WriteOptions|null $options
106106 * @return array(
107107 * @type \DCarbone\PHPConsulAPI\WriteMeta metadata about write
@@ -121,7 +121,7 @@ public function delete($key, WriteOptions $options = null) {
121121 }
122122
123123 /**
124- * @param string $prefix
124+ * @param string $prefix
125125 * @param \DCarbone\PHPConsulAPI\QueryOptions|null $options
126126 * @return array(
127127 * @type KVPair[]|null array of KVPair objects under specified prefix
@@ -171,7 +171,7 @@ public function valueList($prefix = '', QueryOptions $options = null) {
171171 }
172172
173173 /**
174- * @param string $prefix Prefix to search for. Null returns all keys.
174+ * @param string $prefix Prefix to search for. Null returns all keys.
175175 * @param \DCarbone\PHPConsulAPI\QueryOptions $options
176176 * @return array(
177177 * @type string[]|null list of keys
@@ -211,9 +211,10 @@ public function keys($prefix = null, QueryOptions $options = null) {
211211 }
212212
213213 /**
214- * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
214+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
215215 * @param \DCarbone\PHPConsulAPI\WriteOptions $options
216216 * @return array(
217+ * @type bool whether the operation succeeded or not
217218 * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
218219 * @type \DCarbone\PHPConsulAPI\Error|null error, if any
219220 * )
@@ -225,17 +226,16 @@ public function cas(KVPair $p, WriteOptions $options = null) {
225226 if (0 !== $ p ->Flags ) {
226227 $ r ->Params ->set ('flags ' , (string )$ p ->Flags );
227228 }
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 ));
230231 if (null !== $ err ) {
231232 return [null , $ err ];
232233 }
233-
234- return [$ this ->buildWriteMeta ($ duration ), null ];
234+ return [0 === strpos ($ response ->getBody ()->getContents (), 'true ' ), $ this ->buildWriteMeta ($ duration ), null ];
235235 }
236236
237237 /**
238- * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
238+ * @param \DCarbone\PHPConsulAPI\KV\KVPair $p
239239 * @param \DCarbone\PHPConsulAPI\WriteOptions $options
240240 * @return array(
241241 * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -259,7 +259,28 @@ public function acquire(KVPair $p, WriteOptions $options = null) {
259259 }
260260
261261 /**
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
263284 * @param \DCarbone\PHPConsulAPI\WriteOptions $options
264285 * @return array(
265286 * @type \DCarbone\PHPConsulAPI\WriteMeta write metadata
@@ -283,7 +304,7 @@ public function release(KVPair $p, WriteOptions $options = null) {
283304 }
284305
285306 /**
286- * @param null|string $prefix
307+ * @param null|string $prefix
287308 * @param \DCarbone\PHPConsulAPI\QueryOptions $options
288309 * @return array(
289310 * @type KVPair[]|KVTree[]|null array of trees, values, or null on error
0 commit comments