@@ -31,7 +31,6 @@ trait MemcachedTrait
31
31
32
32
private $ client ;
33
33
private $ lazyClient ;
34
- private $ isTextProtocol ;
35
34
36
35
public static function isSupported ()
37
36
{
@@ -50,7 +49,6 @@ private function init(\Memcached $client, $namespace, $defaultLifetime)
50
49
}
51
50
$ this ->maxIdLength -= strlen ($ client ->getOption (\Memcached::OPT_PREFIX_KEY ));
52
51
$ this ->client = $ client ;
53
- $ this ->isTextProtocol = !$ client ->getOption (\Memcached::OPT_BINARY_PROTOCOL );
54
52
} else {
55
53
$ this ->lazyClient = $ client ;
56
54
}
@@ -200,13 +198,12 @@ protected function doSave(array $values, $lifetime)
200
198
$ lifetime += time ();
201
199
}
202
200
203
- if ($ this ->isTextProtocol ) {
204
- $ encoded_values = array ();
205
- array_walk ($ values , function ($ value , $ key ) use (&$ encoded_values ) { $ encoded_values [rawurlencode ($ key )] = $ value ; });
206
- $ values = $ encoded_values ;
201
+ $ encodedValues = array ();
202
+ foreach ($ values as $ key => $ value ) {
203
+ $ encodedValues [rawurlencode ($ key )] = $ value ;
207
204
}
208
205
209
- return $ this ->checkResultCode ($ this ->getClient ()->setMulti ($ values , $ lifetime ));
206
+ return $ this ->checkResultCode ($ this ->getClient ()->setMulti ($ encodedValues , $ lifetime ));
210
207
}
211
208
212
209
/**
@@ -216,11 +213,16 @@ protected function doFetch(array $ids)
216
213
{
217
214
$ unserializeCallbackHandler = ini_set ('unserialize_callback_func ' , __CLASS__ .'::handleUnserializeCallback ' );
218
215
try {
219
- if ($ this ->isTextProtocol ) {
220
- $ ids = array_map ('rawurlencode ' , $ ids );
216
+ $ encodedIds = array_map ('rawurlencode ' , $ ids );
217
+
218
+ $ encodedResult = $ this ->checkResultCode ($ this ->getClient ()->getMulti ($ encodedIds ));
219
+
220
+ $ result = array ();
221
+ foreach ($ encodedResult as $ key => $ value ) {
222
+ $ result [rawurldecode ($ key )] = $ value ;
221
223
}
222
224
223
- return $ this -> checkResultCode ( $ this -> getClient ()-> getMulti ( $ ids )) ;
225
+ return $ result ;
224
226
} catch (\Error $ e ) {
225
227
throw new \ErrorException ($ e ->getMessage (), $ e ->getCode (), E_ERROR , $ e ->getFile (), $ e ->getLine ());
226
228
} finally {
@@ -233,7 +235,7 @@ protected function doFetch(array $ids)
233
235
*/
234
236
protected function doHave ($ id )
235
237
{
236
- return false !== $ this ->getClient ()->get ($ id ) || $ this ->checkResultCode (\Memcached::RES_SUCCESS === $ this ->client ->getResultCode ());
238
+ return false !== $ this ->getClient ()->get (rawurlencode ( $ id) ) || $ this ->checkResultCode (\Memcached::RES_SUCCESS === $ this ->client ->getResultCode ());
237
239
}
238
240
239
241
/**
@@ -242,7 +244,8 @@ protected function doHave($id)
242
244
protected function doDelete (array $ ids )
243
245
{
244
246
$ ok = true ;
245
- foreach ($ this ->checkResultCode ($ this ->getClient ()->deleteMulti ($ ids )) as $ result ) {
247
+ $ encodedIds = array_map ('rawurlencode ' , $ ids );
248
+ foreach ($ this ->checkResultCode ($ this ->getClient ()->deleteMulti ($ encodedIds )) as $ result ) {
246
249
if (\Memcached::RES_SUCCESS !== $ result && \Memcached::RES_NOTFOUND !== $ result ) {
247
250
$ ok = false ;
248
251
}
@@ -287,9 +290,6 @@ private function getClient()
287
290
throw new CacheException (sprintf ('MemcachedAdapter: "prefix_key" option must be empty when using proxified connections, "%s" given. ' , $ prefix ));
288
291
}
289
292
290
- $ this ->client = $ this ->lazyClient ;
291
- $ this ->isTextProtocol = !$ this ->client ->getOption (\Memcached::OPT_BINARY_PROTOCOL );
292
-
293
- return $ this ->client ;
293
+ return $ this ->client = $ this ->lazyClient ;
294
294
}
295
295
}
0 commit comments