@@ -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 | |
@@ -191,9 +191,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | }; |