@@ -96,22 +96,22 @@ discard block |
||
96 | 96 | if ($item instanceof Item) { |
97 | 97 | try { |
98 | 98 | $set = [ |
99 | - self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
100 | - self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
101 | - self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)), |
|
99 | + self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
100 | + self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
101 | + self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)), |
|
102 | 102 | ]; |
103 | 103 | |
104 | 104 | if(!empty($this->config[ 'itemDetailedDate' ])){ |
105 | 105 | $set += [ |
106 | - self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)), |
|
107 | - self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)), |
|
106 | + self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(time() * 1000)), |
|
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 | 111 | $result = (array)$this->getCollection()->updateOne( |
112 | - ['_id' => $item->getEncodedKey()], |
|
113 | - ['$set' => $set], |
|
114 | - ['upsert' => true, 'multiple' => false] |
|
112 | + ['_id' => $item->getEncodedKey()], |
|
113 | + ['$set' => $set], |
|
114 | + ['upsert' => true, 'multiple' => false] |
|
115 | 115 | ); |
116 | 116 | } catch (MongoDBException $e) { |
117 | 117 | throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); |
@@ -133,15 +133,15 @@ discard block |
||
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 | 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 | |
@@ -281,15 +281,15 @@ discard block |
||
281 | 281 | public function getStats() |
282 | 282 | { |
283 | 283 | $serverStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ |
284 | - 'serverStatus' => 1, |
|
285 | - 'recordStats' => 0, |
|
286 | - 'repl' => 0, |
|
287 | - 'metrics' => 0, |
|
284 | + 'serverStatus' => 1, |
|
285 | + 'recordStats' => 0, |
|
286 | + 'repl' => 0, |
|
287 | + 'metrics' => 0, |
|
288 | 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'), |
|
292 | - 'verbose' => true, |
|
291 | + 'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'), |
|
292 | + 'verbose' => true, |
|
293 | 293 | ]))->toArray()[ 0 ]; |
294 | 294 | |
295 | 295 | $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { |
@@ -318,14 +318,14 @@ discard block |
||
318 | 318 | $collectionStats = $array_filter_recursive($collectionStats, $callback); |
319 | 319 | |
320 | 320 | $stats = (new DriverStatistic()) |
321 | - ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400, |
|
322 | - 1) . "\n For more information see RawData.") |
|
323 | - ->setSize($collectionStats->size) |
|
324 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
325 | - ->setRawData([ |
|
321 | + ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400, |
|
322 | + 1) . "\n For more information see RawData.") |
|
323 | + ->setSize($collectionStats->size) |
|
324 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
325 | + ->setRawData([ |
|
326 | 326 | 'serverStatus' => $serverStats, |
327 | 327 | 'collStats' => $collectionStats, |
328 | - ]); |
|
328 | + ]); |
|
329 | 329 | |
330 | 330 | return $stats; |
331 | 331 | } |
@@ -101,14 +101,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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($parameters[ 'collectionName' ]) ? $parameters[ 'collectionName' ] : 'Cache'; |
|
207 | - $databaseName = isset($parameters[ 'databaseName' ]) ? $parameters[ 'databaseName' ] : 'phpFastCache'; |
|
205 | + $timeout = isset($this->config['timeout']) ? $this->config['timeout'] * 1000 : 3000; |
|
206 | + $collectionName = isset($parameters['collectionName']) ? $parameters['collectionName'] : 'Cache'; |
|
207 | + $databaseName = isset($parameters['databaseName']) ? $parameters['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 |
||
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 |
||
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 |
||
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 | }; |