|
@@ -66,7 +66,7 @@ discard block |
|
|
block discarded – undo |
|
66
|
66
|
*/ |
|
67
|
67
|
public function driverCheck() |
|
68
|
68
|
{ |
|
69
|
|
- if(!class_exists('MongoDB\Driver\Manager') && class_exists('MongoClient')){ |
|
|
69
|
+ if (!class_exists('MongoDB\Driver\Manager') && class_exists('MongoClient')) { |
|
70
|
70
|
trigger_error('This driver is used to support the pecl MongoDb extension with mongo-php-library. |
|
71
|
71
|
For MongoDb with Mongo PECL support use Mongo Driver.', E_USER_ERROR); |
|
72
|
72
|
} |
|
@@ -93,7 +93,7 @@ discard block |
|
|
block discarded – undo |
|
93
|
93
|
'$set' => [ |
|
94
|
94
|
self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
95
|
95
|
self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
96
|
|
- self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time()*1000)), |
|
|
96
|
+ self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((time() + $item->getTtl()) * 1000) : new UTCDateTime(time() * 1000)), |
|
97
|
97
|
], |
|
98
|
98
|
], |
|
99
|
99
|
['upsert' => true, 'multiple' => false] |
|
@@ -102,7 +102,7 @@ discard block |
|
|
block discarded – undo |
|
102
|
102
|
throw new phpFastCacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); |
|
103
|
103
|
} |
|
104
|
104
|
|
|
105
|
|
- return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
|
105
|
+ return isset($result['ok']) ? $result['ok'] == 1 : true; |
|
106
|
106
|
} else { |
|
107
|
107
|
throw new phpFastCacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
108
|
108
|
} |
|
@@ -118,9 +118,9 @@ discard block |
|
|
block discarded – undo |
|
118
|
118
|
|
|
119
|
119
|
if ($document) { |
|
120
|
120
|
return [ |
|
121
|
|
- self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
122
|
|
- self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
123
|
|
- self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
|
121
|
+ self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()), |
|
|
122
|
+ self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()), |
|
|
123
|
+ self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()), |
|
124
|
124
|
]; |
|
125
|
125
|
} else { |
|
126
|
126
|
return null; |
|
@@ -158,7 +158,7 @@ discard block |
|
|
block discarded – undo |
|
158
|
158
|
* @var \MongoDB\Model\BSONDocument $result |
|
159
|
159
|
*/ |
|
160
|
160
|
$result = $this->getCollection()->drop()->getArrayCopy(); |
|
161
|
|
- $this->collection = new Collection($this->instance,'phpFastCache','Cache'); |
|
|
161
|
+ $this->collection = new Collection($this->instance, 'phpFastCache', 'Cache'); |
|
162
|
162
|
|
|
163
|
163
|
/** |
|
164
|
164
|
* This will rebuild automatically the Collection indexes |
|
@@ -178,13 +178,13 @@ discard block |
|
|
block discarded – undo |
|
178
|
178
|
if ($this->instance instanceof \MongoDB\Driver\Manager) { |
|
179
|
179
|
throw new LogicException('Already connected to Mongodb server'); |
|
180
|
180
|
} else { |
|
181
|
|
- $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
182
|
|
- $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017'; |
|
183
|
|
- $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : 3; |
|
184
|
|
- $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
185
|
|
- $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
186
|
|
- $collectionName = isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'; |
|
187
|
|
- $databaseName = isset($this->config[ 'databaseName' ]) ? $this->config[ 'databaseName' ] : 'phpFastCache'; |
|
|
181
|
+ $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
|
182
|
+ $port = isset($this->config['port']) ? $this->config['port'] : '27017'; |
|
|
183
|
+ $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 3; |
|
|
184
|
+ $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
|
185
|
+ $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
|
186
|
+ $collectionName = isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'; |
|
|
187
|
+ $databaseName = isset($this->config['databaseName']) ? $this->config['databaseName'] : 'phpFastCache'; |
|
188
|
188
|
|
|
189
|
189
|
|
|
190
|
190
|
/** |
|
@@ -195,7 +195,7 @@ discard block |
|
|
block discarded – undo |
|
195
|
195
|
($password ? ":{$password}" : '') . |
|
196
|
196
|
($username ? '@' : '') . "{$host}" . |
|
197
|
197
|
($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000])); |
|
198
|
|
- $this->collection = $this->collection ?: new Collection($this->instance,$databaseName, $collectionName); |
|
|
198
|
+ $this->collection = $this->collection ?: new Collection($this->instance, $databaseName, $collectionName); |
|
199
|
199
|
|
|
200
|
200
|
return true; |
|
201
|
201
|
} |
|
@@ -229,16 +229,16 @@ discard block |
|
|
block discarded – undo |
|
229
|
229
|
]))->toArray()[0]; |
|
230
|
230
|
|
|
231
|
231
|
$collectionStats = $this->instance->executeCommand('phpFastCache', new Command([ |
|
232
|
|
- 'collStats' => (isset($this->config[ 'collectionName' ]) ? $this->config[ 'collectionName' ] : 'Cache'), |
|
|
232
|
+ 'collStats' => (isset($this->config['collectionName']) ? $this->config['collectionName'] : 'Cache'), |
|
233
|
233
|
'verbose' => true, |
|
234
|
234
|
]))->toArray()[0]; |
|
235
|
235
|
|
|
236
|
|
- $array_filter_recursive = function( $array, callable $callback = null ) use(&$array_filter_recursive) { |
|
|
236
|
+ $array_filter_recursive = function($array, callable $callback = null) use(&$array_filter_recursive) { |
|
237
|
237
|
$array = $callback($array); |
|
238
|
238
|
|
|
239
|
|
- if(is_object($array) ||is_array($array)){ |
|
240
|
|
- foreach ( $array as &$value ) { |
|
241
|
|
- $value = call_user_func( $array_filter_recursive, $value, $callback ); |
|
|
239
|
+ if (is_object($array) || is_array($array)) { |
|
|
240
|
+ foreach ($array as &$value) { |
|
|
241
|
+ $value = call_user_func($array_filter_recursive, $value, $callback); |
|
242
|
242
|
} |
|
243
|
243
|
} |
|
244
|
244
|
|
|
@@ -250,7 +250,7 @@ discard block |
|
|
block discarded – undo |
|
250
|
250
|
/** |
|
251
|
251
|
* Remove unserializable properties |
|
252
|
252
|
*/ |
|
253
|
|
- if($item instanceof \MongoDB\BSON\UTCDateTime){ |
|
|
253
|
+ if ($item instanceof \MongoDB\BSON\UTCDateTime) { |
|
254
|
254
|
return (string) $item; |
|
255
|
255
|
} |
|
256
|
256
|
return $item; |