@@ -128,7 +128,7 @@ |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * @return bool |
|
| 131 | + * @return boolean|null |
|
| 132 | 132 | */ |
| 133 | 133 | public function driverConnect() |
| 134 | 134 | { |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
| 143 | 143 | $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
| 144 | 144 | $buckets = isset($this->config[ 'buckets' ]) ? $this->config[ 'buckets' ] : [ |
| 145 | - [ |
|
| 145 | + [ |
|
| 146 | 146 | 'bucket' => 'default', |
| 147 | 147 | 'password' => '', |
| 148 | - ], |
|
| 148 | + ], |
|
| 149 | 149 | ]; |
| 150 | 150 | |
| 151 | 151 | $this->instance = $this->instance ?: new CouchbaseClient("couchbase://{$host}", $username, $password); |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | $info = $this->getBucket()->manager()->info(); |
| 194 | 194 | |
| 195 | 195 | return (new driverStatistic()) |
| 196 | - ->setSize($info[ 'basicStats' ][ 'diskUsed' ]) |
|
| 197 | - ->setRawData($info) |
|
| 198 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 199 | - ->setInfo('CouchBase version ' . $info[ 'nodes' ][ 0 ][ 'version' ] . ', Uptime (in days): ' . round($info[ 'nodes' ][ 0 ][ 'uptime' ] / 86400, 1) . "\n For more information see RawData."); |
|
| 196 | + ->setSize($info[ 'basicStats' ][ 'diskUsed' ]) |
|
| 197 | + ->setRawData($info) |
|
| 198 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 199 | + ->setInfo('CouchBase version ' . $info[ 'nodes' ][ 0 ][ 'version' ] . ', Uptime (in days): ' . round($info[ 'nodes' ][ 0 ][ 'uptime' ] / 86400, 1) . "\n For more information see RawData."); |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | \ No newline at end of file |
@@ -137,11 +137,11 @@ discard block |
||
| 137 | 137 | } else { |
| 138 | 138 | |
| 139 | 139 | |
| 140 | - $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
| 140 | + $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
| 141 | 141 | //$port = isset($server[ 'port' ]) ? $server[ 'port' ] : '11211'; |
| 142 | - $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
| 143 | - $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
| 144 | - $buckets = isset($this->config[ 'buckets' ]) ? $this->config[ 'buckets' ] : [ |
|
| 142 | + $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
| 143 | + $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
| 144 | + $buckets = isset($this->config['buckets']) ? $this->config['buckets'] : [ |
|
| 145 | 145 | [ |
| 146 | 146 | 'bucket' => 'default', |
| 147 | 147 | 'password' => '', |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | $this->instance = $this->instance ?: new CouchbaseClient("couchbase://{$host}", $username, $password); |
| 152 | 152 | |
| 153 | 153 | foreach ($buckets as $bucket) { |
| 154 | - $this->bucketCurrent = $this->bucketCurrent ?: $bucket[ 'bucket' ]; |
|
| 155 | - $this->setBucket($bucket[ 'bucket' ], $this->instance->openBucket($bucket[ 'bucket' ], $bucket[ 'password' ])); |
|
| 154 | + $this->bucketCurrent = $this->bucketCurrent ?: $bucket['bucket']; |
|
| 155 | + $this->setBucket($bucket['bucket'], $this->instance->openBucket($bucket['bucket'], $bucket['password'])); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected function getBucket() |
| 164 | 164 | { |
| 165 | - return $this->bucketInstances[ $this->bucketCurrent ]; |
|
| 165 | + return $this->bucketInstances[$this->bucketCurrent]; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | protected function setBucket($bucketName, \CouchbaseBucket $CouchbaseBucket) |
| 174 | 174 | { |
| 175 | 175 | if (!array_key_exists($bucketName, $this->bucketInstances)) { |
| 176 | - $this->bucketInstances[ $bucketName ] = $CouchbaseBucket; |
|
| 176 | + $this->bucketInstances[$bucketName] = $CouchbaseBucket; |
|
| 177 | 177 | } else { |
| 178 | 178 | throw new \LogicException('A bucket instance with this name already exists.'); |
| 179 | 179 | } |
@@ -193,9 +193,9 @@ discard block |
||
| 193 | 193 | $info = $this->getBucket()->manager()->info(); |
| 194 | 194 | |
| 195 | 195 | return (new driverStatistic()) |
| 196 | - ->setSize($info[ 'basicStats' ][ 'diskUsed' ]) |
|
| 196 | + ->setSize($info['basicStats']['diskUsed']) |
|
| 197 | 197 | ->setRawData($info) |
| 198 | 198 | ->setData(implode(', ', array_keys($this->itemInstances))) |
| 199 | - ->setInfo('CouchBase version ' . $info[ 'nodes' ][ 0 ][ 'version' ] . ', Uptime (in days): ' . round($info[ 'nodes' ][ 0 ][ 'uptime' ] / 86400, 1) . "\n For more information see RawData."); |
|
| 199 | + ->setInfo('CouchBase version ' . $info['nodes'][0]['version'] . ', Uptime (in days): ' . round($info['nodes'][0]['uptime'] / 86400, 1) . "\n For more information see RawData."); |
|
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | \ No newline at end of file |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | - * @param $keyword |
|
| 214 | + * @param string $keyword |
|
| 215 | 215 | * @param bool $reset |
| 216 | 216 | * @return PDO |
| 217 | 217 | */ |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | 250 | * @param \Psr\Cache\CacheItemInterface $item |
| 251 | - * @return mixed |
|
| 251 | + * @return boolean |
|
| 252 | 252 | * @throws \InvalidArgumentException |
| 253 | 253 | */ |
| 254 | 254 | public function driverWrite(CacheItemInterface $item) |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | - * @return bool |
|
| 402 | + * @return boolean|null |
|
| 403 | 403 | */ |
| 404 | 404 | public function driverConnect() |
| 405 | 405 | { |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); |
| 163 | 163 | $stm->execute(); |
| 164 | 164 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 165 | - if (!isset($row[ 'db' ])) { |
|
| 165 | + if (!isset($row['db'])) { |
|
| 166 | 166 | $db = 1; |
| 167 | - } elseif ($row[ 'db' ] <= 1) { |
|
| 167 | + } elseif ($row['db'] <= 1) { |
|
| 168 | 168 | $db = 1; |
| 169 | 169 | } else { |
| 170 | - $db = $row[ 'db' ]; |
|
| 170 | + $db = $row['db']; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // check file size |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | ':keyword' => $keyword, |
| 190 | 190 | ]); |
| 191 | 191 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 192 | - if (isset($row[ 'db' ]) && $row[ 'db' ] != '') { |
|
| 193 | - $db = $row[ 'db' ]; |
|
| 192 | + if (isset($row['db']) && $row['db'] != '') { |
|
| 193 | + $db = $row['db']; |
|
| 194 | 194 | } else { |
| 195 | 195 | /* |
| 196 | 196 | * Insert new to Indexing |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | /** |
| 222 | 222 | * init instant |
| 223 | 223 | */ |
| 224 | - if (!isset($this->instance[ $instant ])) { |
|
| 224 | + if (!isset($this->instance[$instant])) { |
|
| 225 | 225 | // check DB Files ready or not |
| 226 | 226 | $createTable = false; |
| 227 | 227 | if (!file_exists($this->SqliteDir . '/db' . $instant) || $reset == true) { |
@@ -234,12 +234,12 @@ discard block |
||
| 234 | 234 | $this->initDB($PDO); |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $this->instance[ $instant ] = $PDO; |
|
| 237 | + $this->instance[$instant] = $PDO; |
|
| 238 | 238 | unset($PDO); |
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - return $this->instance[ $instant ]; |
|
| 242 | + return $this->instance[$instant]; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | * Check for Cross-Driver type confusion |
| 254 | 254 | */ |
| 255 | 255 | if ($item instanceof Item) { |
| 256 | - $skipExisting = isset($this->config[ 'skipExisting' ]) ? $this->config[ 'skipExisting' ] : false; |
|
| 256 | + $skipExisting = isset($this->config['skipExisting']) ? $this->config['skipExisting'] : false; |
|
| 257 | 257 | $toWrite = true; |
| 258 | 258 | |
| 259 | 259 | // check in cache first |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - if (isset($row[ 'object' ])) { |
|
| 333 | - return $this->decode($row[ 'object' ]); |
|
| 332 | + if (isset($row['object'])) { |
|
| 333 | + return $this->decode($row['object']); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | return null; |
@@ -16,13 +16,11 @@ |
||
| 16 | 16 | |
| 17 | 17 | use PDO; |
| 18 | 18 | use PDOException; |
| 19 | -use phpFastCache\Core\Item\ExtendedCacheItemInterface; |
|
| 20 | 19 | use phpFastCache\Core\Pool\DriverBaseTrait; |
| 21 | 20 | use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface; |
| 22 | 21 | use phpFastCache\Core\Pool\IO\IOHelperTrait; |
| 23 | 22 | use phpFastCache\Entities\driverStatistic; |
| 24 | 23 | use phpFastCache\Exceptions\phpFastCacheDriverCheckException; |
| 25 | -use phpFastCache\Exceptions\phpFastCacheDriverException; |
|
| 26 | 24 | use phpFastCache\Exceptions\phpFastCacheIOException; |
| 27 | 25 | use phpFastCache\Util\Directory; |
| 28 | 26 | use Psr\Cache\CacheItemInterface; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | $PDO = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE); |
| 155 | 155 | $PDO->setAttribute(PDO::ATTR_ERRMODE, |
| 156 | - PDO::ERRMODE_EXCEPTION); |
|
| 156 | + PDO::ERRMODE_EXCEPTION); |
|
| 157 | 157 | |
| 158 | 158 | if ($createTable == true) { |
| 159 | 159 | $this->initIndexing($PDO); |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | // look for keyword |
| 189 | 189 | $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); |
| 190 | 190 | $stm->execute([ |
| 191 | - ':keyword' => $keyword, |
|
| 191 | + ':keyword' => $keyword, |
|
| 192 | 192 | ]); |
| 193 | 193 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 194 | 194 | if (isset($row[ 'db' ]) && $row[ 'db' ] != '') { |
@@ -200,8 +200,8 @@ discard block |
||
| 200 | 200 | $db = $this->currentDB; |
| 201 | 201 | $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); |
| 202 | 202 | $stm->execute([ |
| 203 | - ':keyword' => $keyword, |
|
| 204 | - ':db' => $db, |
|
| 203 | + ':keyword' => $keyword, |
|
| 204 | + ':db' => $db, |
|
| 205 | 205 | ]); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -272,11 +272,11 @@ discard block |
||
| 272 | 272 | if ($toWrite == true) { |
| 273 | 273 | try { |
| 274 | 274 | $stm = $this->getDb($item->getKey()) |
| 275 | - ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 275 | + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 276 | 276 | $stm->execute([ |
| 277 | - ':keyword' => $item->getKey(), |
|
| 278 | - ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 279 | - ':exp' => time() + $item->getTtl(), |
|
| 277 | + ':keyword' => $item->getKey(), |
|
| 278 | + ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 279 | + ':exp' => time() + $item->getTtl(), |
|
| 280 | 280 | ]); |
| 281 | 281 | |
| 282 | 282 | return true; |
@@ -284,11 +284,11 @@ discard block |
||
| 284 | 284 | |
| 285 | 285 | try { |
| 286 | 286 | $stm = $this->getDb($item->getKey(), true) |
| 287 | - ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 287 | + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 288 | 288 | $stm->execute([ |
| 289 | - ':keyword' => $item->getKey(), |
|
| 290 | - ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 291 | - ':exp' => time() + $item->getTtl(), |
|
| 289 | + ':keyword' => $item->getKey(), |
|
| 290 | + ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 291 | + ':exp' => time() + $item->getTtl(), |
|
| 292 | 292 | ]); |
| 293 | 293 | } catch (PDOException $e) { |
| 294 | 294 | return false; |
@@ -310,20 +310,20 @@ discard block |
||
| 310 | 310 | { |
| 311 | 311 | try { |
| 312 | 312 | $stm = $this->getDb($item->getKey()) |
| 313 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword AND (`exp` >= :U) LIMIT 1"); |
|
| 313 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword AND (`exp` >= :U) LIMIT 1"); |
|
| 314 | 314 | $stm->execute([ |
| 315 | - ':keyword' => $item->getKey(), |
|
| 316 | - ':U' => time(), |
|
| 315 | + ':keyword' => $item->getKey(), |
|
| 316 | + ':U' => time(), |
|
| 317 | 317 | ]); |
| 318 | 318 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 319 | 319 | |
| 320 | 320 | } catch (PDOException $e) { |
| 321 | 321 | try { |
| 322 | 322 | $stm = $this->getDb($item->getKey(), true) |
| 323 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword AND (`exp` >= :U) LIMIT 1"); |
|
| 323 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword AND (`exp` >= :U) LIMIT 1"); |
|
| 324 | 324 | $stm->execute([ |
| 325 | - ':keyword' => $item->getKey(), |
|
| 326 | - ':U' => time(), |
|
| 325 | + ':keyword' => $item->getKey(), |
|
| 326 | + ':U' => time(), |
|
| 327 | 327 | ]); |
| 328 | 328 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 329 | 329 | } catch (PDOException $e) { |
@@ -351,13 +351,13 @@ discard block |
||
| 351 | 351 | if ($item instanceof Item) { |
| 352 | 352 | try { |
| 353 | 353 | $stm = $this->getDb($item->getKey()) |
| 354 | - //->prepare("DELETE FROM `caching` WHERE (`id`=:id) OR (`exp` <= :U) "); |
|
| 355 | - ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); |
|
| 354 | + //->prepare("DELETE FROM `caching` WHERE (`id`=:id) OR (`exp` <= :U) "); |
|
| 355 | + ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); |
|
| 356 | 356 | |
| 357 | 357 | return $stm->execute([ |
| 358 | 358 | // ':id' => $row[ 'id' ], |
| 359 | - ':keyword' => $item->getKey(), |
|
| 360 | - ':U' => time(), |
|
| 359 | + ':keyword' => $item->getKey(), |
|
| 360 | + ':U' => time(), |
|
| 361 | 361 | ]); |
| 362 | 362 | } catch (PDOException $e) { |
| 363 | 363 | return false; |
@@ -420,11 +420,11 @@ discard block |
||
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | $stat->setData(implode(', ', array_keys($this->itemInstances))) |
| 423 | - ->setRawData([ |
|
| 423 | + ->setRawData([ |
|
| 424 | 424 | 'tmp' => $this->tmp |
| 425 | - ]) |
|
| 426 | - ->setSize(Directory::dirSize($path)) |
|
| 427 | - ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
| 425 | + ]) |
|
| 426 | + ->setSize(Directory::dirSize($path)) |
|
| 427 | + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
| 428 | 428 | |
| 429 | 429 | return $stat; |
| 430 | 430 | } |
@@ -42,7 +42,7 @@ |
||
| 42 | 42 | $this->driver->setItem($this); |
| 43 | 43 | } else { |
| 44 | 44 | throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', |
| 45 | - gettype($key))); |
|
| 45 | + gettype($key))); |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | |
@@ -128,7 +128,7 @@ |
||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | - * @return bool |
|
| 131 | + * @return boolean|null |
|
| 132 | 132 | */ |
| 133 | 133 | public function driverConnect() |
| 134 | 134 | { |
@@ -176,9 +176,9 @@ |
||
| 176 | 176 | public function getStats() |
| 177 | 177 | { |
| 178 | 178 | return (new driverStatistic()) |
| 179 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 180 | - ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($this->getLeveldbFile())) |
|
| 181 | - ->setSize(Directory::dirSize($this->getLeveldbFile())); |
|
| 179 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 180 | + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($this->getLeveldbFile())) |
|
| 181 | + ->setSize(Directory::dirSize($this->getLeveldbFile())); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -83,8 +83,8 @@ |
||
| 83 | 83 | |
| 84 | 84 | $files = new RecursiveIteratorIterator |
| 85 | 85 | ( |
| 86 | - new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 87 | - RecursiveIteratorIterator::CHILD_FIRST |
|
| 86 | + new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), |
|
| 87 | + RecursiveIteratorIterator::CHILD_FIRST |
|
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | 90 | foreach ($files as $fileinfo) { |
@@ -81,8 +81,7 @@ |
||
| 81 | 81 | return unlink($source); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $files = new RecursiveIteratorIterator |
|
| 85 | - ( |
|
| 84 | + $files = new RecursiveIteratorIterator( |
|
| 86 | 85 | new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), |
| 87 | 86 | RecursiveIteratorIterator::CHILD_FIRST |
| 88 | 87 | ); |
@@ -140,9 +140,9 @@ |
||
| 140 | 140 | { |
| 141 | 141 | $stat = new driverStatistic(); |
| 142 | 142 | $stat->setInfo('[Devnull] A void info string') |
| 143 | - ->setSize(0) |
|
| 144 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 145 | - ->setRawData(null); |
|
| 143 | + ->setSize(0) |
|
| 144 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 145 | + ->setRawData(null); |
|
| 146 | 146 | |
| 147 | 147 | return $stat; |
| 148 | 148 | } |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @param \Psr\Cache\CacheItemInterface $item |
| 60 | - * @return mixed |
|
| 60 | + * @return boolean |
|
| 61 | 61 | * @throws \InvalidArgumentException |
| 62 | 62 | */ |
| 63 | 63 | public function driverWrite(CacheItemInterface $item) |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * @param \Psr\Cache\CacheItemInterface $item |
| 56 | - * @return mixed |
|
| 56 | + * @return boolean |
|
| 57 | 57 | * @throws \InvalidArgumentException |
| 58 | 58 | */ |
| 59 | 59 | public function driverWrite(CacheItemInterface $item) |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * @param \Psr\Cache\CacheItemInterface $item |
| 115 | - * @return bool |
|
| 115 | + * @return boolean|null |
|
| 116 | 116 | * @throws \InvalidArgumentException |
| 117 | 117 | */ |
| 118 | 118 | public function driverIsHit(CacheItemInterface $item) |
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | if ($item instanceof Item) { |
| 84 | 84 | try { |
| 85 | 85 | $result = (array) $this->getCollection()->update( |
| 86 | - ['_id' => $item->getKey()], |
|
| 87 | - [ |
|
| 86 | + ['_id' => $item->getKey()], |
|
| 87 | + [ |
|
| 88 | 88 | '$set' => [ |
| 89 | - self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())), |
|
| 90 | - self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), |
|
| 91 | - self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY), |
|
| 89 | + self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())), |
|
| 90 | + self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), |
|
| 91 | + self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY), |
|
| 92 | 92 | ], |
| 93 | - ], |
|
| 94 | - ['upsert' => true, 'multiple' => false] |
|
| 93 | + ], |
|
| 94 | + ['upsert' => true, 'multiple' => false] |
|
| 95 | 95 | ); |
| 96 | 96 | } catch (MongoCursorException $e) { |
| 97 | 97 | return false; |
@@ -110,14 +110,14 @@ discard block |
||
| 110 | 110 | protected function driverRead(CacheItemInterface $item) |
| 111 | 111 | { |
| 112 | 112 | $document = $this->getCollection() |
| 113 | - ->findOne(['_id' => $item->getKey()], |
|
| 113 | + ->findOne(['_id' => $item->getKey()], |
|
| 114 | 114 | [self::DRIVER_DATA_WRAPPER_INDEX, self::DRIVER_EDATE_WRAPPER_INDEX, self::DRIVER_TAGS_WRAPPER_INDEX /*'d', 'e'*/]); |
| 115 | 115 | |
| 116 | 116 | if ($document) { |
| 117 | 117 | return [ |
| 118 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin), |
|
| 119 | - self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->sec), |
|
| 120 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin), |
|
| 118 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin), |
|
| 119 | + self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->sec), |
|
| 120 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin), |
|
| 121 | 121 | ]; |
| 122 | 122 | } else { |
| 123 | 123 | return null; |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | * @todo make an url builder |
| 173 | 173 | */ |
| 174 | 174 | $this->instance = $this->instance ?: (new MongodbClient('mongodb://' . |
| 175 | - ($username ?: '') . |
|
| 176 | - ($password ? ":{$password}" : '') . |
|
| 177 | - ($username ? '@' : '') . "{$host}" . |
|
| 178 | - ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache; |
|
| 175 | + ($username ?: '') . |
|
| 176 | + ($password ? ":{$password}" : '') . |
|
| 177 | + ($username ? '@' : '') . "{$host}" . |
|
| 178 | + ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache; |
|
| 179 | 179 | // $this->instance->Cache->createIndex([self::DRIVER_TIME_WRAPPER_INDEX => 1], ['expireAfterSeconds' => 0]); |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -201,25 +201,25 @@ discard block |
||
| 201 | 201 | public function getStats() |
| 202 | 202 | { |
| 203 | 203 | $serverStatus = $this->getCollection()->db->command([ |
| 204 | - 'serverStatus' => 1, |
|
| 205 | - 'recordStats' => 0, |
|
| 206 | - 'repl' => 0, |
|
| 207 | - 'metrics' => 0, |
|
| 204 | + 'serverStatus' => 1, |
|
| 205 | + 'recordStats' => 0, |
|
| 206 | + 'repl' => 0, |
|
| 207 | + 'metrics' => 0, |
|
| 208 | 208 | ]); |
| 209 | 209 | |
| 210 | 210 | $collStats = $this->getCollection()->db->command([ |
| 211 | - 'collStats' => 'Cache', |
|
| 212 | - 'verbose' => true, |
|
| 211 | + 'collStats' => 'Cache', |
|
| 212 | + 'verbose' => true, |
|
| 213 | 213 | ]); |
| 214 | 214 | |
| 215 | 215 | $stats = (new driverStatistic()) |
| 216 | - ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
| 217 | - ->setSize((int) @$collStats[ 'size' ]) |
|
| 218 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 219 | - ->setRawData([ |
|
| 216 | + ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
| 217 | + ->setSize((int) @$collStats[ 'size' ]) |
|
| 218 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 219 | + ->setRawData([ |
|
| 220 | 220 | 'serverStatus' => $serverStatus, |
| 221 | 221 | 'collStats' => $collStats, |
| 222 | - ]); |
|
| 222 | + ]); |
|
| 223 | 223 | |
| 224 | 224 | return $stats; |
| 225 | 225 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | public function driverCheck() |
| 64 | 64 | { |
| 65 | - if(class_exists('MongoDB\Driver\Manager')){ |
|
| 65 | + if (class_exists('MongoDB\Driver\Manager')) { |
|
| 66 | 66 | trigger_error('PhpFastCache currently only support the pecl Mongo extension.<br /> |
| 67 | 67 | The Support for the MongoDB extension will be added coming soon.', E_USER_ERROR); |
| 68 | 68 | } |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | return false; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
| 100 | + return isset($result['ok']) ? $result['ok'] == 1 : true; |
|
| 101 | 101 | } else { |
| 102 | 102 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
| 103 | 103 | } |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | if ($document) { |
| 117 | 117 | return [ |
| 118 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin), |
|
| 119 | - self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->sec), |
|
| 120 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin), |
|
| 118 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->bin), |
|
| 119 | + self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->sec), |
|
| 120 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->bin), |
|
| 121 | 121 | ]; |
| 122 | 122 | } else { |
| 123 | 123 | return null; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | if ($item instanceof Item) { |
| 138 | 138 | $deletionResult = (array) $this->getCollection()->remove(['_id' => $item->getKey()], ["w" => 1]); |
| 139 | 139 | |
| 140 | - return (int) $deletionResult[ 'ok' ] === 1 && !$deletionResult[ 'err' ]; |
|
| 140 | + return (int) $deletionResult['ok'] === 1 && !$deletionResult['err']; |
|
| 141 | 141 | } else { |
| 142 | 142 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
| 143 | 143 | } |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | if ($this->instance instanceof MongodbClient) { |
| 162 | 162 | throw new LogicException('Already connected to Mongodb server'); |
| 163 | 163 | } else { |
| 164 | - $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
| 165 | - $port = isset($this->config[ 'port' ]) ? $this->config[ 'port' ] : '27017'; |
|
| 166 | - $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : 3; |
|
| 167 | - $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
| 168 | - $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
| 164 | + $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
| 165 | + $port = isset($this->config['port']) ? $this->config['port'] : '27017'; |
|
| 166 | + $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : 3; |
|
| 167 | + $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
| 168 | + $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
| 169 | 169 | |
| 170 | 170 | |
| 171 | 171 | /** |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | ]); |
| 214 | 214 | |
| 215 | 215 | $stats = (new driverStatistic()) |
| 216 | - ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
| 217 | - ->setSize((int) @$collStats[ 'size' ]) |
|
| 216 | + ->setInfo('MongoDB version ' . $serverStatus['version'] . ', Uptime (in days): ' . round($serverStatus['uptime'] / 86400, 1) . "\n For more information see RawData.") |
|
| 217 | + ->setSize((int) @$collStats['size']) |
|
| 218 | 218 | ->setData(implode(', ', array_keys($this->itemInstances))) |
| 219 | 219 | ->setRawData([ |
| 220 | 220 | 'serverStatus' => $serverStatus, |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | if (!is_object($driverInstance)) { |
| 24 | 24 | echo '[FAIL] CacheManager::getInstance() returned an invalid variable type:' . gettype($driverInstance) . "\n"; |
| 25 | 25 | $status = 1; |
| 26 | -}else if(!($driverInstance instanceof CacheItemPoolInterface)){ |
|
| 26 | +} else if (!($driverInstance instanceof CacheItemPoolInterface)) { |
|
| 27 | 27 | echo '[FAIL] CacheManager::getInstance() returned an invalid class:' . get_class($driverInstance) . "\n"; |
| 28 | 28 | $status = 1; |
| 29 | -}else{ |
|
| 29 | +} else { |
|
| 30 | 30 | echo '[PASS] CacheManager::getInstance() returned a valid CacheItemPoolInterface object: ' . get_class($driverInstance) . "\n"; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -23,10 +23,10 @@ |
||
| 23 | 23 | if (!is_object($driverInstance)) { |
| 24 | 24 | echo '[FAIL] CacheManager::getInstance() returned an invalid variable type:' . gettype($driverInstance) . "\n"; |
| 25 | 25 | $status = 1; |
| 26 | -}else if(!($driverInstance instanceof CacheItemPoolInterface)){ |
|
| 26 | +} else if(!($driverInstance instanceof CacheItemPoolInterface)){ |
|
| 27 | 27 | echo '[FAIL] CacheManager::getInstance() returned an invalid class:' . get_class($driverInstance) . "\n"; |
| 28 | 28 | $status = 1; |
| 29 | -}else{ |
|
| 29 | +} else{ |
|
| 30 | 30 | echo '[PASS] CacheManager::getInstance() returned a valid CacheItemPoolInterface object: ' . get_class($driverInstance) . "\n"; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -159,9 +159,9 @@ |
||
| 159 | 159 | $date = (new \DateTime())->setTimestamp(time() - $info[ 'uptime_in_seconds' ]); |
| 160 | 160 | |
| 161 | 161 | return (new driverStatistic()) |
| 162 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 163 | - ->setRawData($info) |
|
| 164 | - ->setSize($info[ 'used_memory' ]) |
|
| 165 | - ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $info[ 'redis_version' ], $date->format(DATE_RFC2822))); |
|
| 162 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 163 | + ->setRawData($info) |
|
| 164 | + ->setSize($info[ 'used_memory' ]) |
|
| 165 | + ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $info[ 'redis_version' ], $date->format(DATE_RFC2822))); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | \ No newline at end of file |
@@ -122,11 +122,11 @@ discard block |
||
| 122 | 122 | } else { |
| 123 | 123 | $this->instance = $this->instance ?: new RedisClient(); |
| 124 | 124 | |
| 125 | - $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
| 126 | - $port = isset($this->config[ 'port' ]) ? (int) $this->config[ 'port' ] : '6379'; |
|
| 127 | - $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
| 128 | - $database = isset($this->config[ 'database' ]) ? $this->config[ 'database' ] : ''; |
|
| 129 | - $timeout = isset($this->config[ 'timeout' ]) ? $this->config[ 'timeout' ] : ''; |
|
| 125 | + $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
| 126 | + $port = isset($this->config['port']) ? (int) $this->config['port'] : '6379'; |
|
| 127 | + $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
| 128 | + $database = isset($this->config['database']) ? $this->config['database'] : ''; |
|
| 129 | + $timeout = isset($this->config['timeout']) ? $this->config['timeout'] : ''; |
|
| 130 | 130 | |
| 131 | 131 | if (!$this->instance->connect($host, (int) $port, (int) $timeout)) { |
| 132 | 132 | return false; |
@@ -156,12 +156,12 @@ discard block |
||
| 156 | 156 | { |
| 157 | 157 | // used_memory |
| 158 | 158 | $info = $this->instance->info(); |
| 159 | - $date = (new \DateTime())->setTimestamp(time() - $info[ 'uptime_in_seconds' ]); |
|
| 159 | + $date = (new \DateTime())->setTimestamp(time() - $info['uptime_in_seconds']); |
|
| 160 | 160 | |
| 161 | 161 | return (new driverStatistic()) |
| 162 | 162 | ->setData(implode(', ', array_keys($this->itemInstances))) |
| 163 | 163 | ->setRawData($info) |
| 164 | - ->setSize($info[ 'used_memory' ]) |
|
| 165 | - ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $info[ 'redis_version' ], $date->format(DATE_RFC2822))); |
|
| 164 | + ->setSize($info['used_memory']) |
|
| 165 | + ->setInfo(sprintf("The Redis daemon v%s is up since %s.\n For more information see RawData. \n Driver size includes the memory allocation size.", $info['redis_version'], $date->format(DATE_RFC2822))); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | \ No newline at end of file |