@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | if (!class_exists('phpFastCache\CacheManager')) { |
| 19 | 19 | echo "[FAIL] Autoload failed to find the CacheManager\n"; |
| 20 | 20 | $status = 255; |
| 21 | -}else{ |
|
| 21 | +} else { |
|
| 22 | 22 | echo "[PASS] Autoload successfully found the CacheManager\n"; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | if (!interface_exists('Psr\Cache\CacheItemInterface')) { |
| 29 | 29 | echo "[FAIL] Autoload failed to find the Psr CacheItemInterface\n"; |
| 30 | 30 | $status = 255; |
| 31 | -}else{ |
|
| 31 | +} else { |
|
| 32 | 32 | echo "[PASS] Autoload successfully found the Psr CacheItemInterface\n"; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | if (!class_exists('phpFastCache\CacheManager')) { |
| 19 | 19 | echo "[FAIL] Autoload failed to find the CacheManager\n"; |
| 20 | 20 | $status = 255; |
| 21 | -}else{ |
|
| 21 | +} else{ |
|
| 22 | 22 | echo "[PASS] Autoload successfully found the CacheManager\n"; |
| 23 | 23 | } |
| 24 | 24 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | if (!interface_exists('Psr\Cache\CacheItemInterface')) { |
| 29 | 29 | echo "[FAIL] Autoload failed to find the Psr CacheItemInterface\n"; |
| 30 | 30 | $status = 255; |
| 31 | -}else{ |
|
| 31 | +} else{ |
|
| 32 | 32 | echo "[PASS] Autoload successfully found the Psr CacheItemInterface\n"; |
| 33 | 33 | } |
| 34 | 34 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512) |
| 49 | 49 | { |
| 50 | - $callback = function(CacheItemInterface $item){ |
|
| 50 | + $callback = function(CacheItemInterface $item) { |
|
| 51 | 51 | return $item->get(); |
| 52 | 52 | }; |
| 53 | 53 | return json_encode(array_map($callback, array_values($this->getItems($keys))), $option, $depth); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * |
| 76 | 76 | * #headache |
| 77 | 77 | */ |
| 78 | - return array_filter($this->getItems(array_unique(array_keys($items))), function(ExtendedCacheItemInterface $item){ |
|
| 78 | + return array_filter($this->getItems(array_unique(array_keys($items))), function(ExtendedCacheItemInterface $item) { |
|
| 79 | 79 | return $item->isHit(); |
| 80 | 80 | }); |
| 81 | 81 | } else { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
| 119 | 119 | { |
| 120 | - $callback = function(CacheItemInterface $item){ |
|
| 120 | + $callback = function(CacheItemInterface $item) { |
|
| 121 | 121 | return $item->get(); |
| 122 | 122 | }; |
| 123 | 123 | |
@@ -302,15 +302,15 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | protected function deregisterItem($item) |
| 304 | 304 | { |
| 305 | - if($item instanceof CacheItemInterface){ |
|
| 306 | - unset($this->itemInstances[ $item->getKey() ]); |
|
| 305 | + if ($item instanceof CacheItemInterface) { |
|
| 306 | + unset($this->itemInstances[$item->getKey()]); |
|
| 307 | 307 | |
| 308 | - }else if(is_string($item)){ |
|
| 309 | - unset($this->itemInstances[ $item ]); |
|
| 310 | - }else{ |
|
| 308 | + } else if (is_string($item)) { |
|
| 309 | + unset($this->itemInstances[$item]); |
|
| 310 | + } else { |
|
| 311 | 311 | throw new \InvalidArgumentException('Invalid type for $item variable'); |
| 312 | 312 | } |
| 313 | - if(gc_enabled()){ |
|
| 313 | + if (gc_enabled()) { |
|
| 314 | 314 | gc_collect_cycles(); |
| 315 | 315 | } |
| 316 | 316 | } |
@@ -305,9 +305,9 @@ |
||
| 305 | 305 | if($item instanceof CacheItemInterface){ |
| 306 | 306 | unset($this->itemInstances[ $item->getKey() ]); |
| 307 | 307 | |
| 308 | - }else if(is_string($item)){ |
|
| 308 | + } else if(is_string($item)){ |
|
| 309 | 309 | unset($this->itemInstances[ $item ]); |
| 310 | - }else{ |
|
| 310 | + } else{ |
|
| 311 | 311 | throw new \InvalidArgumentException('Invalid type for $item variable'); |
| 312 | 312 | } |
| 313 | 313 | if(gc_enabled()){ |
@@ -42,10 +42,10 @@ |
||
| 42 | 42 | if (!is_object($driverInstance->getItem('test'))) { |
| 43 | 43 | echo '[FAIL] $driverInstance->getItem() returned an invalid var type:' . gettype($driverInstance) . "\n"; |
| 44 | 44 | $status = 1; |
| 45 | -}else if(!($driverInstance->getItem('test') instanceof ExtendedCacheItemInterface)){ |
|
| 45 | +} else if (!($driverInstance->getItem('test') instanceof ExtendedCacheItemInterface)) { |
|
| 46 | 46 | echo '[FAIL] $driverInstance->getItem() returned an invalid class that does not implements ExtendedCacheItemInterface: ' . get_class($driverInstance) . "\n"; |
| 47 | 47 | $status = 1; |
| 48 | -}else{ |
|
| 48 | +} else { |
|
| 49 | 49 | echo '[PASS] $driverInstance->getItem() returned a valid class that implements ExtendedCacheItemInterface: ' . get_class($driverInstance) . "\n"; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -42,10 +42,10 @@ |
||
| 42 | 42 | if (!is_object($driverInstance->getItem('test'))) { |
| 43 | 43 | echo '[FAIL] $driverInstance->getItem() returned an invalid var type:' . gettype($driverInstance) . "\n"; |
| 44 | 44 | $status = 1; |
| 45 | -}else if(!($driverInstance->getItem('test') instanceof ExtendedCacheItemInterface)){ |
|
| 45 | +} else if(!($driverInstance->getItem('test') instanceof ExtendedCacheItemInterface)){ |
|
| 46 | 46 | echo '[FAIL] $driverInstance->getItem() returned an invalid class that does not implements ExtendedCacheItemInterface: ' . get_class($driverInstance) . "\n"; |
| 47 | 47 | $status = 1; |
| 48 | -}else{ |
|
| 48 | +} else{ |
|
| 49 | 49 | echo '[PASS] $driverInstance->getItem() returned a valid class that implements ExtendedCacheItemInterface: ' . get_class($driverInstance) . "\n"; |
| 50 | 50 | } |
| 51 | 51 | |
@@ -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) |
@@ -78,15 +78,15 @@ discard block |
||
| 78 | 78 | if ($item instanceof Item) { |
| 79 | 79 | try { |
| 80 | 80 | $result = (array) $this->getCollection()->update( |
| 81 | - ['_id' => $item->getKey()], |
|
| 82 | - [ |
|
| 81 | + ['_id' => $item->getKey()], |
|
| 82 | + [ |
|
| 83 | 83 | '$set' => [ |
| 84 | - self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())), |
|
| 85 | - self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), |
|
| 86 | - self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY), |
|
| 84 | + self::DRIVER_TIME_WRAPPER_INDEX => ($item->getTtl() > 0 ? new MongoDate(time() + $item->getTtl()) : new MongoDate(time())), |
|
| 85 | + self::DRIVER_DATA_WRAPPER_INDEX => new MongoBinData($this->encode($item->get()), MongoBinData::BYTE_ARRAY), |
|
| 86 | + self::DRIVER_TAGS_WRAPPER_INDEX => new MongoBinData($this->encode($item->getTags()), MongoBinData::BYTE_ARRAY), |
|
| 87 | 87 | ], |
| 88 | - ], |
|
| 89 | - ['upsert' => true, 'multiple' => false] |
|
| 88 | + ], |
|
| 89 | + ['upsert' => true, 'multiple' => false] |
|
| 90 | 90 | ); |
| 91 | 91 | } catch (MongoCursorException $e) { |
| 92 | 92 | return false; |
@@ -105,14 +105,14 @@ discard block |
||
| 105 | 105 | protected function driverRead(CacheItemInterface $item) |
| 106 | 106 | { |
| 107 | 107 | $document = $this->getCollection() |
| 108 | - ->findOne(['_id' => $item->getKey()], |
|
| 108 | + ->findOne(['_id' => $item->getKey()], |
|
| 109 | 109 | [self::DRIVER_DATA_WRAPPER_INDEX, self::DRIVER_TIME_WRAPPER_INDEX, self::DRIVER_TAGS_WRAPPER_INDEX /*'d', 'e'*/]); |
| 110 | 110 | |
| 111 | 111 | if ($document) { |
| 112 | 112 | return [ |
| 113 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin), |
|
| 114 | - self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec), |
|
| 115 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin), |
|
| 113 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin), |
|
| 114 | + self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec), |
|
| 115 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin), |
|
| 116 | 116 | ]; |
| 117 | 117 | } else { |
| 118 | 118 | return null; |
@@ -167,10 +167,10 @@ discard block |
||
| 167 | 167 | * @todo make an url builder |
| 168 | 168 | */ |
| 169 | 169 | $this->instance = $this->instance ?: (new MongodbClient('mongodb://' . |
| 170 | - ($username ?: '') . |
|
| 171 | - ($password ? ":{$password}" : '') . |
|
| 172 | - ($username ? '@' : '') . "{$host}" . |
|
| 173 | - ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache; |
|
| 170 | + ($username ?: '') . |
|
| 171 | + ($password ? ":{$password}" : '') . |
|
| 172 | + ($username ? '@' : '') . "{$host}" . |
|
| 173 | + ($port != '27017' ? ":{$port}" : ''), ['connectTimeoutMS' => $timeout * 1000]))->phpFastCache; |
|
| 174 | 174 | // $this->instance->Cache->createIndex([self::DRIVER_TIME_WRAPPER_INDEX => 1], ['expireAfterSeconds' => 0]); |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -196,25 +196,25 @@ discard block |
||
| 196 | 196 | public function getStats() |
| 197 | 197 | { |
| 198 | 198 | $serverStatus = $this->getCollection()->db->command([ |
| 199 | - 'serverStatus' => 1, |
|
| 200 | - 'recordStats' => 0, |
|
| 201 | - 'repl' => 0, |
|
| 202 | - 'metrics' => 0, |
|
| 199 | + 'serverStatus' => 1, |
|
| 200 | + 'recordStats' => 0, |
|
| 201 | + 'repl' => 0, |
|
| 202 | + 'metrics' => 0, |
|
| 203 | 203 | ]); |
| 204 | 204 | |
| 205 | 205 | $collStats = $this->getCollection()->db->command([ |
| 206 | - 'collStats' => 'Cache', |
|
| 207 | - 'verbose' => true, |
|
| 206 | + 'collStats' => 'Cache', |
|
| 207 | + 'verbose' => true, |
|
| 208 | 208 | ]); |
| 209 | 209 | |
| 210 | 210 | $stats = (new driverStatistic()) |
| 211 | - ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
| 212 | - ->setSize((int) @$collStats[ 'size' ]) |
|
| 213 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 214 | - ->setRawData([ |
|
| 211 | + ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
| 212 | + ->setSize((int) @$collStats[ 'size' ]) |
|
| 213 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 214 | + ->setRawData([ |
|
| 215 | 215 | 'serverStatus' => $serverStatus, |
| 216 | 216 | 'collStats' => $collStats, |
| 217 | - ]); |
|
| 217 | + ]); |
|
| 218 | 218 | |
| 219 | 219 | return $stats; |
| 220 | 220 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function driverCheck() |
| 61 | 61 | { |
| 62 | - if(class_exists('MongoDB\Driver\Manager')){ |
|
| 62 | + if (class_exists('MongoDB\Driver\Manager')) { |
|
| 63 | 63 | trigger_error('PhpFastCache currently only support the pecl Mongo extension.<br /> |
| 64 | 64 | The Support for the MongoDB extension will be added coming soon.', E_USER_ERROR); |
| 65 | 65 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
| 97 | + return isset($result['ok']) ? $result['ok'] == 1 : true; |
|
| 98 | 98 | } else { |
| 99 | 99 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
| 100 | 100 | } |
@@ -112,9 +112,9 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | if ($document) { |
| 114 | 114 | return [ |
| 115 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->bin), |
|
| 116 | - self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_TIME_WRAPPER_INDEX ]->sec), |
|
| 117 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->bin), |
|
| 115 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->bin), |
|
| 116 | + self::DRIVER_TIME_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_TIME_WRAPPER_INDEX]->sec), |
|
| 117 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->bin), |
|
| 118 | 118 | ]; |
| 119 | 119 | } else { |
| 120 | 120 | return null; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | if ($item instanceof Item) { |
| 135 | 135 | $deletionResult = (array) $this->getCollection()->remove(['_id' => $item->getKey()], ["w" => 1]); |
| 136 | 136 | |
| 137 | - return (int) $deletionResult[ 'ok' ] === 1 && !$deletionResult[ 'err' ]; |
|
| 137 | + return (int) $deletionResult['ok'] === 1 && !$deletionResult['err']; |
|
| 138 | 138 | } else { |
| 139 | 139 | throw new \InvalidArgumentException('Cross-Driver type confusion detected'); |
| 140 | 140 | } |
@@ -158,11 +158,11 @@ discard block |
||
| 158 | 158 | if ($this->instance instanceof MongodbClient) { |
| 159 | 159 | throw new LogicException('Already connected to Mongodb server'); |
| 160 | 160 | } else { |
| 161 | - $host = isset($this->config[ 'host' ]) ? $this->config[ 'host' ] : '127.0.0.1'; |
|
| 162 | - $port = isset($server[ 'port' ]) ? $server[ 'port' ] : '27017'; |
|
| 163 | - $timeout = isset($server[ 'timeout' ]) ? $server[ 'timeout' ] : 3; |
|
| 164 | - $password = isset($this->config[ 'password' ]) ? $this->config[ 'password' ] : ''; |
|
| 165 | - $username = isset($this->config[ 'username' ]) ? $this->config[ 'username' ] : ''; |
|
| 161 | + $host = isset($this->config['host']) ? $this->config['host'] : '127.0.0.1'; |
|
| 162 | + $port = isset($server['port']) ? $server['port'] : '27017'; |
|
| 163 | + $timeout = isset($server['timeout']) ? $server['timeout'] : 3; |
|
| 164 | + $password = isset($this->config['password']) ? $this->config['password'] : ''; |
|
| 165 | + $username = isset($this->config['username']) ? $this->config['username'] : ''; |
|
| 166 | 166 | |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | ]); |
| 211 | 211 | |
| 212 | 212 | $stats = (new driverStatistic()) |
| 213 | - ->setInfo('MongoDB version ' . $serverStatus[ 'version' ] . ', Uptime (in days): ' . round($serverStatus[ 'uptime' ] / 86400, 1) . "\n For more information see RawData.") |
|
| 214 | - ->setSize((int) @$collStats[ 'size' ]) |
|
| 213 | + ->setInfo('MongoDB version ' . $serverStatus['version'] . ', Uptime (in days): ' . round($serverStatus['uptime'] / 86400, 1) . "\n For more information see RawData.") |
|
| 214 | + ->setSize((int) @$collStats['size']) |
|
| 215 | 215 | ->setData(implode(', ', array_keys($this->itemInstances))) |
| 216 | 216 | ->setRawData([ |
| 217 | 217 | 'serverStatus' => $serverStatus, |