|
@@ -101,14 +101,14 @@ discard block |
|
|
block discarded – undo |
|
101
|
101
|
self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)), |
|
102
|
102
|
]; |
|
103
|
103
|
|
|
104
|
|
- if(!empty($this->config[ 'itemDetailedDate' ])){ |
|
|
104
|
+ if (!empty($this->config['itemDetailedDate'])) { |
|
105
|
105
|
$set += [ |
|
106
|
106
|
self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)), |
|
107
|
107
|
self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)), |
|
108
|
108
|
]; |
|
109
|
109
|
} |
|
110
|
110
|
|
|
111
|
|
- $result = (array)$this->getCollection()->updateOne( |
|
|
111
|
+ $result = (array) $this->getCollection()->updateOne( |
|
112
|
112
|
['_id' => $item->getEncodedKey()], |
|
113
|
113
|
['$set' => $set], |
|
114
|
114
|
['upsert' => true, 'multiple' => false] |
|
@@ -117,7 +117,7 @@ discard block |
|
|
block discarded – undo |
|
117
|
117
|
throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); |
|
118
|
118
|
} |
|
119
|
119
|
|
|
120
|
|
- return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
|
120
|
+ return isset($result['ok']) ? $result['ok'] == 1 : true; |
|
121
|
121
|
} else { |
|
122
|
122
|
throw new phpFastCacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
123
|
123
|
} |
|
@@ -133,15 +133,15 @@ discard block |
|
|
block discarded – undo |
|
133
|
133
|
|
|
134
|
134
|
if ($document) { |
|
135
|
135
|
$return = [ |
|
136
|
|
- self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
137
|
|
- self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
138
|
|
- self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
|
136
|
+ self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()), |
|
|
137
|
+ self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()), |
|
|
138
|
+ self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()), |
|
139
|
139
|
]; |
|
140
|
140
|
|
|
141
|
|
- if(!empty($this->config[ 'itemDetailedDate' ])){ |
|
|
141
|
+ if (!empty($this->config['itemDetailedDate'])) { |
|
142
|
142
|
$return += [ |
|
143
|
|
- self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
144
|
|
- self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
|
143
|
+ self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_MDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()), |
|
|
144
|
+ self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_CDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()), |
|
145
|
145
|
]; |
|
146
|
146
|
} |
|
147
|
147
|
|
|
@@ -189,7 +189,7 @@ discard block |
|
|
block discarded – undo |
|
189
|
189
|
*/ |
|
190
|
190
|
$this->save($this->getItem('__PFC_CACHE_CLEARED__')->set(true)); |
|
191
|
191
|
|
|
192
|
|
- return !empty($result[ 'ok' ]); |
|
|
192
|
+ return !empty($result['ok']); |
|
193
|
193
|
} |
|
194
|
194
|
|
|
195
|
195
|
/** |
|
@@ -202,9 +202,9 @@ discard block |
|
|
block discarded – undo |
|
202
|
202
|
if ($this->instance instanceof \MongoDB\Driver\Manager) { |
|
203
|
203
|
throw new LogicException('Already connected to Mongodb server'); |
|
204
|
204
|
} else { |
|
205
|
|
- $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] * 1000 : 3000; |
|
206
|
|
- $collectionName = isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'; |
|
207
|
|
- $databaseName = isset($this->config[ 'databaseName' ]) ? $this->config[ 'databaseName' ] : 'phpFastCache'; |
|
|
205
|
+ $timeout = isset($this->config['timeout']) ? $this->config['timeout'] * 1000 : 3000; |
|
|
206
|
+ $collectionName = isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'; |
|
|
207
|
+ $databaseName = isset($this->config['databaseName']) ? $this->config['databaseName'] : 'phpFastCache'; |
|
208
|
208
|
|
|
209
|
209
|
$this->instance = $this->instance ?: (new Client($this->buildConnectionURI(), ['connectTimeoutMS' => $timeout])); |
|
210
|
210
|
$this->database = $this->database ?: $this->instance->selectDatabase($databaseName); |
|
@@ -244,10 +244,10 @@ discard block |
|
|
block discarded – undo |
|
244
|
244
|
*/ |
|
245
|
245
|
protected function buildConnectionURI() |
|
246
|
246
|
{ |
|
247
|
|
- $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
248
|
|
- $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017'; |
|
249
|
|
- $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
250
|
|
- $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
|
247
|
+ $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
|
248
|
+ $port = isset($this->config['port']) ? $this->config['port'] : '27017'; |
|
|
249
|
+ $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
|
250
|
+ $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
251
|
251
|
|
|
252
|
252
|
$parts = [ |
|
253
|
253
|
'mongodb://', |
|
@@ -285,14 +285,14 @@ discard block |
|
|
block discarded – undo |
|
285
|
285
|
'recordStats' => 0, |
|
286
|
286
|
'repl' => 0, |
|
287
|
287
|
'metrics' => 0, |
|
288
|
|
- ]))->toArray()[ 0 ]; |
|
|
288
|
+ ]))->toArray()[0]; |
|
289
|
289
|
|
|
290
|
290
|
$collectionStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ |
|
291
|
|
- 'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'), |
|
|
291
|
+ 'collStats' => (isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'), |
|
292
|
292
|
'verbose' => true, |
|
293
|
|
- ]))->toArray()[ 0 ]; |
|
|
293
|
+ ]))->toArray()[0]; |
|
294
|
294
|
|
|
295
|
|
- $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { |
|
|
295
|
+ $array_filter_recursive = function($array, callable $callback = null) use (&$array_filter_recursive) { |
|
296
|
296
|
$array = $callback($array); |
|
297
|
297
|
|
|
298
|
298
|
if (is_object($array) || is_array($array)) { |
|
@@ -304,12 +304,12 @@ discard block |
|
|
block discarded – undo |
|
304
|
304
|
return $array; |
|
305
|
305
|
}; |
|
306
|
306
|
|
|
307
|
|
- $callback = function ($item) { |
|
|
307
|
+ $callback = function($item) { |
|
308
|
308
|
/** |
|
309
|
309
|
* Remove unserializable properties |
|
310
|
310
|
*/ |
|
311
|
311
|
if ($item instanceof \MongoDB\BSON\UTCDateTime) { |
|
312
|
|
- return (string)$item; |
|
|
312
|
+ return (string) $item; |
|
313
|
313
|
} |
|
314
|
314
|
return $item; |
|
315
|
315
|
}; |