@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | |
19 | 19 | use LogicException; |
20 | 20 | use MongoDB\{ |
21 | - Client, Database, BSON\Binary, BSON\UTCDateTime, Collection, DeleteResult, Driver\Command, Driver\Exception\Exception as MongoDBException |
|
21 | + Client, Database, BSON\Binary, BSON\UTCDateTime, Collection, DeleteResult, Driver\Command, Driver\Exception\Exception as MongoDBException |
|
22 | 22 | }; |
23 | 23 | use Phpfastcache\Core\Pool\{ |
24 | - DriverBaseTrait, ExtendedCacheItemPoolInterface |
|
24 | + DriverBaseTrait, ExtendedCacheItemPoolInterface |
|
25 | 25 | }; |
26 | 26 | use Phpfastcache\Entities\DriverStatistic; |
27 | 27 | use Phpfastcache\Exceptions\{ |
28 | - PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException |
|
28 | + PhpfastcacheDriverException, PhpfastcacheInvalidArgumentException |
|
29 | 29 | }; |
30 | 30 | |
31 | 31 | use Psr\Cache\CacheItemInterface; |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | |
79 | 79 | if ($document) { |
80 | 80 | $return = [ |
81 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
82 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
83 | - self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
81 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
82 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
83 | + self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
84 | 84 | ]; |
85 | 85 | |
86 | 86 | if(!empty($this->getConfigOption('itemDetailedDate'))){ |
87 | 87 | $return += [ |
88 | - self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime() |
|
88 | + self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime() |
|
89 | 89 | ->getTimestamp()), |
90 | - self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime() |
|
90 | + self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime() |
|
91 | 91 | ->getTimestamp()), |
92 | 92 | ]; |
93 | 93 | } |
@@ -112,23 +112,23 @@ discard block |
||
112 | 112 | if ($item instanceof Item) { |
113 | 113 | try { |
114 | 114 | $set = [ |
115 | - self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
116 | - self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
117 | - self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((\time() + $item->getTtl()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
115 | + self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
116 | + self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
117 | + self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((\time() + $item->getTtl()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
118 | 118 | ]; |
119 | 119 | |
120 | 120 | if(!empty($this->getConfigOption('itemDetailedDate'))){ |
121 | 121 | $set += [ |
122 | - self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
123 | - self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
122 | + self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
123 | + self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
124 | 124 | ]; |
125 | 125 | } |
126 | 126 | $result = (array)$this->getCollection()->updateOne( |
127 | - ['_id' => $item->getEncodedKey()], |
|
128 | - [ |
|
127 | + ['_id' => $item->getEncodedKey()], |
|
128 | + [ |
|
129 | 129 | '$set' => $set, |
130 | - ], |
|
131 | - ['upsert' => true, 'multiple' => false] |
|
130 | + ], |
|
131 | + ['upsert' => true, 'multiple' => false] |
|
132 | 132 | ); |
133 | 133 | } catch (MongoDBException $e) { |
134 | 134 | throw new PhpfastcacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); |
@@ -229,13 +229,13 @@ discard block |
||
229 | 229 | $password = $this->getConfigOption('password'); |
230 | 230 | |
231 | 231 | return implode('', [ |
232 | - 'mongodb://', |
|
233 | - ($username ?: ''), |
|
234 | - ($password ? ":{$password}" : ''), |
|
235 | - ($username ? '@' : ''), |
|
236 | - $host, |
|
237 | - ($port !== 27017 ? ":{$port}" : ''), |
|
238 | - ($databaseName ? "/{$databaseName}" : '') |
|
232 | + 'mongodb://', |
|
233 | + ($username ?: ''), |
|
234 | + ($password ? ":{$password}" : ''), |
|
235 | + ($username ? '@' : ''), |
|
236 | + $host, |
|
237 | + ($port !== 27017 ? ":{$port}" : ''), |
|
238 | + ($databaseName ? "/{$databaseName}" : '') |
|
239 | 239 | ]); |
240 | 240 | } |
241 | 241 | |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | public function getStats(): DriverStatistic |
260 | 260 | { |
261 | 261 | $serverStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ |
262 | - 'serverStatus' => 1, |
|
263 | - 'recordStats' => 0, |
|
264 | - 'repl' => 0, |
|
265 | - 'metrics' => 0, |
|
262 | + 'serverStatus' => 1, |
|
263 | + 'recordStats' => 0, |
|
264 | + 'repl' => 0, |
|
265 | + 'metrics' => 0, |
|
266 | 266 | ]))->toArray()[ 0 ]; |
267 | 267 | |
268 | 268 | $collectionStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ |
269 | - 'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'), |
|
270 | - 'verbose' => true, |
|
269 | + 'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'), |
|
270 | + 'verbose' => true, |
|
271 | 271 | ]))->toArray()[ 0 ]; |
272 | 272 | |
273 | 273 | $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { |
@@ -296,14 +296,14 @@ discard block |
||
296 | 296 | $collectionStats = $array_filter_recursive($collectionStats, $callback); |
297 | 297 | |
298 | 298 | $stats = (new DriverStatistic()) |
299 | - ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . \round($serverStats->uptime / 86400, |
|
300 | - 1) . "\n For more information see RawData.") |
|
301 | - ->setSize($collectionStats->size) |
|
302 | - ->setData(\implode(', ', \array_keys($this->itemInstances))) |
|
303 | - ->setRawData([ |
|
299 | + ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . \round($serverStats->uptime / 86400, |
|
300 | + 1) . "\n For more information see RawData.") |
|
301 | + ->setSize($collectionStats->size) |
|
302 | + ->setData(\implode(', ', \array_keys($this->itemInstances))) |
|
303 | + ->setRawData([ |
|
304 | 304 | 'serverStatus' => $serverStats, |
305 | 305 | 'collStats' => $collectionStats, |
306 | - ]); |
|
306 | + ]); |
|
307 | 307 | |
308 | 308 | return $stats; |
309 | 309 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @author Fabio Covolo Mazzo (fabiocmazzo) <[email protected]> |
13 | 13 | * |
14 | 14 | */ |
15 | -declare(strict_types=1); |
|
15 | +declare(strict_types = 1); |
|
16 | 16 | |
17 | 17 | namespace Phpfastcache\Drivers\Mongodb; |
18 | 18 | |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | |
79 | 79 | if ($document) { |
80 | 80 | $return = [ |
81 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
82 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
83 | - self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
81 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()), |
|
82 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()), |
|
83 | + self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()), |
|
84 | 84 | ]; |
85 | 85 | |
86 | - if(!empty($this->getConfigOption('itemDetailedDate'))){ |
|
86 | + if (!empty($this->getConfigOption('itemDetailedDate'))) { |
|
87 | 87 | $return += [ |
88 | - self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime() |
|
88 | + self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_MDATE_WRAPPER_INDEX]->toDateTime() |
|
89 | 89 | ->getTimestamp()), |
90 | - self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime() |
|
90 | + self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_CDATE_WRAPPER_INDEX]->toDateTime() |
|
91 | 91 | ->getTimestamp()), |
92 | 92 | ]; |
93 | 93 | } |
@@ -117,13 +117,13 @@ discard block |
||
117 | 117 | self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((\time() + $item->getTtl()) * 1000) : new UTCDateTime(\time() * 1000)), |
118 | 118 | ]; |
119 | 119 | |
120 | - if(!empty($this->getConfigOption('itemDetailedDate'))){ |
|
120 | + if (!empty($this->getConfigOption('itemDetailedDate'))) { |
|
121 | 121 | $set += [ |
122 | 122 | self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
123 | 123 | self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
124 | 124 | ]; |
125 | 125 | } |
126 | - $result = (array)$this->getCollection()->updateOne( |
|
126 | + $result = (array) $this->getCollection()->updateOne( |
|
127 | 127 | ['_id' => $item->getEncodedKey()], |
128 | 128 | [ |
129 | 129 | '$set' => $set, |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | throw new PhpfastcacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); |
135 | 135 | } |
136 | 136 | |
137 | - return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
137 | + return isset($result['ok']) ? $result['ok'] == 1 : true; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | { |
226 | 226 | $host = $this->getConfigOption('host'); |
227 | 227 | $port = $this->getConfigOption('port'); |
228 | - $username = $this->getConfigOption('username'); |
|
228 | + $username = $this->getConfigOption('username'); |
|
229 | 229 | $password = $this->getConfigOption('password'); |
230 | 230 | |
231 | 231 | return implode('', [ |
@@ -263,14 +263,14 @@ discard block |
||
263 | 263 | 'recordStats' => 0, |
264 | 264 | 'repl' => 0, |
265 | 265 | 'metrics' => 0, |
266 | - ]))->toArray()[ 0 ]; |
|
266 | + ]))->toArray()[0]; |
|
267 | 267 | |
268 | 268 | $collectionStats = $this->instance->getManager()->executeCommand('phpFastCache', new Command([ |
269 | - 'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'), |
|
269 | + 'collStats' => (isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'), |
|
270 | 270 | 'verbose' => true, |
271 | - ]))->toArray()[ 0 ]; |
|
271 | + ]))->toArray()[0]; |
|
272 | 272 | |
273 | - $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { |
|
273 | + $array_filter_recursive = function($array, callable $callback = null) use (&$array_filter_recursive) { |
|
274 | 274 | $array = $callback($array); |
275 | 275 | |
276 | 276 | if (\is_object($array) || \is_array($array)) { |
@@ -282,12 +282,12 @@ discard block |
||
282 | 282 | return $array; |
283 | 283 | }; |
284 | 284 | |
285 | - $callback = function ($item) { |
|
285 | + $callback = function($item) { |
|
286 | 286 | /** |
287 | 287 | * Remove unserializable properties |
288 | 288 | */ |
289 | 289 | if ($item instanceof \MongoDB\BSON\UTCDateTime) { |
290 | - return (string)$item; |
|
290 | + return (string) $item; |
|
291 | 291 | } |
292 | 292 | return $item; |
293 | 293 | }; |