@@ -1097,234 +1097,6 @@ protected function internalRemoveItems(array &$normalizedKeys)
1097
1097
return $ result ;
1098
1098
}
1099
1099
1100
- /**
1101
- * Increment an item.
1102
- *
1103
- * @param string $key
1104
- * @param int $value
1105
- * @return int|bool The new value on success, false on failure
1106
- * @throws Exception\ExceptionInterface
1107
- * @triggers incrementItem.pre(PreEvent)
1108
- * @triggers incrementItem.post(PostEvent)
1109
- * @triggers incrementItem.exception(ExceptionEvent)
1110
- */
1111
- public function incrementItem ($ key , $ value )
1112
- {
1113
- if (! $ this ->getOptions ()->getWritable ()) {
1114
- return false ;
1115
- }
1116
-
1117
- $ this ->normalizeKey ($ key );
1118
- $ args = new ArrayObject ([
1119
- 'key ' => &$ key ,
1120
- 'value ' => &$ value ,
1121
- ]);
1122
-
1123
- try {
1124
- $ eventRs = $ this ->triggerPre (__FUNCTION__ , $ args );
1125
-
1126
- $ result = $ eventRs ->stopped ()
1127
- ? $ eventRs ->last ()
1128
- : $ this ->internalIncrementItem ($ args ['key ' ], $ args ['value ' ]);
1129
-
1130
- return $ this ->triggerPost (__FUNCTION__ , $ args , $ result );
1131
- } catch (\Exception $ e ) {
1132
- $ result = false ;
1133
- return $ this ->triggerException (__FUNCTION__ , $ args , $ result , $ e );
1134
- }
1135
- }
1136
-
1137
- /**
1138
- * Internal method to increment an item.
1139
- *
1140
- * @param string $normalizedKey
1141
- * @param int $value
1142
- * @return int|bool The new value on success, false on failure
1143
- * @throws Exception\ExceptionInterface
1144
- */
1145
- protected function internalIncrementItem (&$ normalizedKey , &$ value )
1146
- {
1147
- $ success = null ;
1148
- $ value = (int ) $ value ;
1149
- $ get = (int ) $ this ->internalGetItem ($ normalizedKey , $ success );
1150
- $ newValue = $ get + $ value ;
1151
-
1152
- if ($ success ) {
1153
- $ this ->internalReplaceItem ($ normalizedKey , $ newValue );
1154
- } else {
1155
- $ this ->internalAddItem ($ normalizedKey , $ newValue );
1156
- }
1157
-
1158
- return $ newValue ;
1159
- }
1160
-
1161
- /**
1162
- * Increment multiple items.
1163
- *
1164
- * @param array $keyValuePairs
1165
- * @return array Associative array of keys and new values
1166
- * @throws Exception\ExceptionInterface
1167
- * @triggers incrementItems.pre(PreEvent)
1168
- * @triggers incrementItems.post(PostEvent)
1169
- * @triggers incrementItems.exception(ExceptionEvent)
1170
- */
1171
- public function incrementItems (array $ keyValuePairs )
1172
- {
1173
- if (! $ this ->getOptions ()->getWritable ()) {
1174
- return [];
1175
- }
1176
-
1177
- $ this ->normalizeKeyValuePairs ($ keyValuePairs );
1178
- $ args = new ArrayObject ([
1179
- 'keyValuePairs ' => &$ keyValuePairs ,
1180
- ]);
1181
-
1182
- try {
1183
- $ eventRs = $ this ->triggerPre (__FUNCTION__ , $ args );
1184
-
1185
- $ result = $ eventRs ->stopped ()
1186
- ? $ eventRs ->last ()
1187
- : $ this ->internalIncrementItems ($ args ['keyValuePairs ' ]);
1188
-
1189
- return $ this ->triggerPost (__FUNCTION__ , $ args , $ result );
1190
- } catch (\Exception $ e ) {
1191
- $ result = [];
1192
- return $ this ->triggerException (__FUNCTION__ , $ args , $ result , $ e );
1193
- }
1194
- }
1195
-
1196
- /**
1197
- * Internal method to increment multiple items.
1198
- *
1199
- * @return array Associative array of keys and new values
1200
- * @throws Exception\ExceptionInterface
1201
- */
1202
- protected function internalIncrementItems (array &$ normalizedKeyValuePairs )
1203
- {
1204
- $ result = [];
1205
- foreach ($ normalizedKeyValuePairs as $ normalizedKey => $ value ) {
1206
- $ newValue = $ this ->internalIncrementItem ($ normalizedKey , $ value );
1207
- if ($ newValue !== false ) {
1208
- $ result [$ normalizedKey ] = $ newValue ;
1209
- }
1210
- }
1211
- return $ result ;
1212
- }
1213
-
1214
- /**
1215
- * Decrement an item.
1216
- *
1217
- * @param string $key
1218
- * @param int $value
1219
- * @return int|bool The new value on success, false on failure
1220
- * @throws Exception\ExceptionInterface
1221
- * @triggers decrementItem.pre(PreEvent)
1222
- * @triggers decrementItem.post(PostEvent)
1223
- * @triggers decrementItem.exception(ExceptionEvent)
1224
- */
1225
- public function decrementItem ($ key , $ value )
1226
- {
1227
- if (! $ this ->getOptions ()->getWritable ()) {
1228
- return false ;
1229
- }
1230
-
1231
- $ this ->normalizeKey ($ key );
1232
- $ args = new ArrayObject ([
1233
- 'key ' => &$ key ,
1234
- 'value ' => &$ value ,
1235
- ]);
1236
-
1237
- try {
1238
- $ eventRs = $ this ->triggerPre (__FUNCTION__ , $ args );
1239
-
1240
- $ result = $ eventRs ->stopped ()
1241
- ? $ eventRs ->last ()
1242
- : $ this ->internalDecrementItem ($ args ['key ' ], $ args ['value ' ]);
1243
-
1244
- return $ this ->triggerPost (__FUNCTION__ , $ args , $ result );
1245
- } catch (\Exception $ e ) {
1246
- $ result = false ;
1247
- return $ this ->triggerException (__FUNCTION__ , $ args , $ result , $ e );
1248
- }
1249
- }
1250
-
1251
- /**
1252
- * Internal method to decrement an item.
1253
- *
1254
- * @param string $normalizedKey
1255
- * @param int $value
1256
- * @return int|bool The new value on success, false on failure
1257
- * @throws Exception\ExceptionInterface
1258
- */
1259
- protected function internalDecrementItem (&$ normalizedKey , &$ value )
1260
- {
1261
- $ success = null ;
1262
- $ value = (int ) $ value ;
1263
- $ get = (int ) $ this ->internalGetItem ($ normalizedKey , $ success );
1264
- $ newValue = $ get - $ value ;
1265
-
1266
- if ($ success ) {
1267
- $ this ->internalReplaceItem ($ normalizedKey , $ newValue );
1268
- } else {
1269
- $ this ->internalAddItem ($ normalizedKey , $ newValue );
1270
- }
1271
-
1272
- return $ newValue ;
1273
- }
1274
-
1275
- /**
1276
- * Decrement multiple items.
1277
- *
1278
- * @param array $keyValuePairs
1279
- * @return array Associative array of keys and new values
1280
- * @throws Exception\ExceptionInterface
1281
- * @triggers incrementItems.pre(PreEvent)
1282
- * @triggers incrementItems.post(PostEvent)
1283
- * @triggers incrementItems.exception(ExceptionEvent)
1284
- */
1285
- public function decrementItems (array $ keyValuePairs )
1286
- {
1287
- if (! $ this ->getOptions ()->getWritable ()) {
1288
- return [];
1289
- }
1290
-
1291
- $ this ->normalizeKeyValuePairs ($ keyValuePairs );
1292
- $ args = new ArrayObject ([
1293
- 'keyValuePairs ' => &$ keyValuePairs ,
1294
- ]);
1295
-
1296
- try {
1297
- $ eventRs = $ this ->triggerPre (__FUNCTION__ , $ args );
1298
-
1299
- $ result = $ eventRs ->stopped ()
1300
- ? $ eventRs ->last ()
1301
- : $ this ->internalDecrementItems ($ args ['keyValuePairs ' ]);
1302
-
1303
- return $ this ->triggerPost (__FUNCTION__ , $ args , $ result );
1304
- } catch (\Exception $ e ) {
1305
- $ result = [];
1306
- return $ this ->triggerException (__FUNCTION__ , $ args , $ result , $ e );
1307
- }
1308
- }
1309
-
1310
- /**
1311
- * Internal method to decrement multiple items.
1312
- *
1313
- * @return array Associative array of keys and new values
1314
- * @throws Exception\ExceptionInterface
1315
- */
1316
- protected function internalDecrementItems (array &$ normalizedKeyValuePairs )
1317
- {
1318
- $ result = [];
1319
- foreach ($ normalizedKeyValuePairs as $ normalizedKey => $ value ) {
1320
- $ newValue = $ this ->internalDecrementItem ($ normalizedKey , $ value );
1321
- if ($ newValue !== false ) {
1322
- $ result [$ normalizedKey ] = $ newValue ;
1323
- }
1324
- }
1325
- return $ result ;
1326
- }
1327
-
1328
1100
/* status */
1329
1101
1330
1102
/**
0 commit comments