|
@@ -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
|
|
|
@@ -191,9 +191,9 @@ discard block |
|
|
block discarded – undo |
|
191
|
191
|
if ($this->instance instanceof \MongoDB\Driver\Manager) { |
|
192
|
192
|
throw new LogicException('Already connected to Mongodb server'); |
|
193
|
193
|
} else { |
|
194
|
|
- $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] * 1000 : 3000; |
|
195
|
|
- $collectionName = isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'; |
|
196
|
|
- $databaseName = isset($this->config[ 'databaseName' ]) ? $this->config[ 'databaseName' ] : 'phpFastCache'; |
|
|
194
|
+ $timeout = isset($this->config['timeout']) ? $this->config['timeout'] * 1000 : 3000; |
|
|
195
|
+ $collectionName = isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'; |
|
|
196
|
+ $databaseName = isset($this->config['databaseName']) ? $this->config['databaseName'] : 'phpFastCache'; |
|
197
|
197
|
|
|
198
|
198
|
$this->instance = $this->instance ?: (new Client($this->buildConnectionURI($databaseName), ['connectTimeoutMS' => $timeout])); |
|
199
|
199
|
$this->database = $this->database ?: $this->instance->selectDatabase($databaseName); |
|
@@ -234,10 +234,10 @@ discard block |
|
|
block discarded – undo |
|
234
|
234
|
*/ |
|
235
|
235
|
protected function buildConnectionURI($databaseName = '') |
|
236
|
236
|
{ |
|
237
|
|
- $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
238
|
|
- $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017'; |
|
239
|
|
- $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
240
|
|
- $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
|
237
|
+ $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
|
238
|
+ $port = isset($this->config['port']) ? $this->config['port'] : '27017'; |
|
|
239
|
+ $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
|
240
|
+ $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
241
|
241
|
|
|
242
|
242
|
$parts = [ |
|
243
|
243
|
'mongodb://', |
|
@@ -276,14 +276,14 @@ discard block |
|
|
block discarded – undo |
|
276
|
276
|
'recordStats' => 0, |
|
277
|
277
|
'repl' => 0, |
|
278
|
278
|
'metrics' => 0, |
|
279
|
|
- ]))->toArray()[ 0 ]; |
|
|
279
|
+ ]))->toArray()[0]; |
|
280
|
280
|
|
|
281
|
281
|
$collectionStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ |
|
282
|
|
- 'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'), |
|
|
282
|
+ 'collStats' => (isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'), |
|
283
|
283
|
'verbose' => true, |
|
284
|
|
- ]))->toArray()[ 0 ]; |
|
|
284
|
+ ]))->toArray()[0]; |
|
285
|
285
|
|
|
286
|
|
- $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { |
|
|
286
|
+ $array_filter_recursive = function($array, callable $callback = null) use (&$array_filter_recursive) { |
|
287
|
287
|
$array = $callback($array); |
|
288
|
288
|
|
|
289
|
289
|
if (is_object($array) || is_array($array)) { |
|
@@ -295,12 +295,12 @@ discard block |
|
|
block discarded – undo |
|
295
|
295
|
return $array; |
|
296
|
296
|
}; |
|
297
|
297
|
|
|
298
|
|
- $callback = function ($item) { |
|
|
298
|
+ $callback = function($item) { |
|
299
|
299
|
/** |
|
300
|
300
|
* Remove unserializable properties |
|
301
|
301
|
*/ |
|
302
|
302
|
if ($item instanceof \MongoDB\BSON\UTCDateTime) { |
|
303
|
|
- return (string)$item; |
|
|
303
|
+ return (string) $item; |
|
304
|
304
|
} |
|
305
|
305
|
return $item; |
|
306
|
306
|
}; |