@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | use Phpfastcache\Entities\ItemBatch; |
| 22 | 22 | use Phpfastcache\Util\ClassNamespaceResolverTrait; |
| 23 | 23 | use Phpfastcache\Exceptions\{ |
| 24 | - PhpfastcacheInvalidArgumentException, PhpfastcacheCoreException, PhpfastcacheLogicException |
|
| 24 | + PhpfastcacheInvalidArgumentException, PhpfastcacheCoreException, PhpfastcacheLogicException |
|
| 25 | 25 | }; |
| 26 | 26 | use Phpfastcache\Config\ConfigurationOption; |
| 27 | 27 | use Psr\Cache\CacheItemInterface; |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | if ($driverArray) { |
| 91 | 91 | if (!\is_array($driverArray)) { |
| 92 | 92 | throw new PhpfastcacheCoreException(\sprintf('The driverRead method returned an unexpected variable type: %s', |
| 93 | - \gettype($driverArray))); |
|
| 93 | + \gettype($driverArray))); |
|
| 94 | 94 | } |
| 95 | 95 | $driverData = $this->driverUnwrapData($driverArray); |
| 96 | 96 | |
@@ -155,9 +155,9 @@ discard block |
||
| 155 | 155 | * Reset the Item |
| 156 | 156 | */ |
| 157 | 157 | $item->set(null) |
| 158 | - ->expiresAfter(\abs((int)$this->getConfig()[ 'defaultTtl' ])) |
|
| 159 | - ->setHit(false) |
|
| 160 | - ->setTags([]); |
|
| 158 | + ->expiresAfter(\abs((int)$this->getConfig()[ 'defaultTtl' ])) |
|
| 159 | + ->setHit(false) |
|
| 160 | + ->setTags([]); |
|
| 161 | 161 | if ($this->getConfigOption( 'itemDetailedDate')) { |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -341,8 +341,8 @@ discard block |
||
| 341 | 341 | $class = new \ReflectionClass((new \ReflectionObject($this))->getNamespaceName() . '\Item'); |
| 342 | 342 | $itemBatch = $class->newInstanceArgs([$this, $item->getKey()]); |
| 343 | 343 | $itemBatch->setEventManager($this->eventManager) |
| 344 | - ->set(new ItemBatch($item->getKey(), new \DateTime())) |
|
| 345 | - ->expiresAfter($this->getConfigOption('cacheSlamsTimeout')); |
|
| 344 | + ->set(new ItemBatch($item->getKey(), new \DateTime())) |
|
| 345 | + ->expiresAfter($this->getConfigOption('cacheSlamsTimeout')); |
|
| 346 | 346 | |
| 347 | 347 | /** |
| 348 | 348 | * To avoid SPL mismatches |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @author Georges.L (Geolim4) <[email protected]> |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -declare(strict_types=1); |
|
| 14 | +declare(strict_types = 1); |
|
| 15 | 15 | |
| 16 | 16 | namespace Phpfastcache\Core\Pool; |
| 17 | 17 | |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * due to performance issue on huge |
| 72 | 72 | * loop dispatching operations |
| 73 | 73 | */ |
| 74 | - if (!isset($this->itemInstances[ $key ])) { |
|
| 74 | + if (!isset($this->itemInstances[$key])) { |
|
| 75 | 75 | if (\preg_match('~([' . \preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)) { |
| 76 | - throw new PhpfastcacheInvalidArgumentException('Unsupported key character detected: "' . $matches[ 1 ] . '". Please check: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Unsupported-characters-in-key-identifiers'); |
|
| 76 | + throw new PhpfastcacheInvalidArgumentException('Unsupported key character detected: "' . $matches[1] . '". Please check: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Unsupported-characters-in-key-identifiers'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | CacheManager::$ReadHits++; |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | $driverData = $this->driverUnwrapData($driverArray); |
| 96 | 96 | |
| 97 | - if ($this->getConfig()[ 'preventCacheSlams' ]) { |
|
| 97 | + if ($this->getConfig()['preventCacheSlams']) { |
|
| 98 | 98 | while ($driverData instanceof ItemBatch) { |
| 99 | 99 | if ($driverData->getItemDate()->getTimestamp() + $this->getConfigOption('cacheSlamsTimeout') < \time()) { |
| 100 | 100 | /** |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $item->set($driverData); |
| 129 | 129 | $item->expiresAt($this->driverUnwrapEdate($driverArray)); |
| 130 | 130 | |
| 131 | - if ($this->getConfigOption( 'itemDetailedDate')) { |
|
| 131 | + if ($this->getConfigOption('itemDetailedDate')) { |
|
| 132 | 132 | /** |
| 133 | 133 | * If the itemDetailedDate has been |
| 134 | 134 | * set after caching, we MUST inject |
@@ -155,10 +155,10 @@ discard block |
||
| 155 | 155 | * Reset the Item |
| 156 | 156 | */ |
| 157 | 157 | $item->set(null) |
| 158 | - ->expiresAfter(\abs((int)$this->getConfig()[ 'defaultTtl' ])) |
|
| 158 | + ->expiresAfter(\abs((int) $this->getConfig()['defaultTtl'])) |
|
| 159 | 159 | ->setHit(false) |
| 160 | 160 | ->setTags([]); |
| 161 | - if ($this->getConfigOption( 'itemDetailedDate')) { |
|
| 161 | + if ($this->getConfigOption('itemDetailedDate')) { |
|
| 162 | 162 | |
| 163 | 163 | /** |
| 164 | 164 | * If the itemDetailedDate has been |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | $item->setHit(true); |
| 173 | 173 | } |
| 174 | 174 | } else { |
| 175 | - $item->expiresAfter(abs((int)$this->getConfig()[ 'defaultTtl' ])); |
|
| 175 | + $item->expiresAfter(abs((int) $this->getConfig()['defaultTtl'])); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | } |
@@ -185,9 +185,9 @@ discard block |
||
| 185 | 185 | * @param $this ExtendedCacheItemPoolInterface |
| 186 | 186 | * @param $this ExtendedCacheItemInterface |
| 187 | 187 | */ |
| 188 | - $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[ $key ]); |
|
| 188 | + $this->eventManager->dispatch('CacheGetItem', $this, $this->itemInstances[$key]); |
|
| 189 | 189 | |
| 190 | - return $this->itemInstances[ $key ]; |
|
| 190 | + return $this->itemInstances[$key]; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | public function setItem(CacheItemInterface $item) |
| 199 | 199 | { |
| 200 | 200 | if ($this->getClassNamespace() . '\\Item' === \get_class($item)) { |
| 201 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
| 201 | + $this->itemInstances[$item->getKey()] = $item; |
|
| 202 | 202 | |
| 203 | 203 | return $this; |
| 204 | 204 | } |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | { |
| 216 | 216 | $collection = []; |
| 217 | 217 | foreach ($keys as $key) { |
| 218 | - $collection[ $key ] = $this->getItem($key); |
|
| 218 | + $collection[$key] = $this->getItem($key); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | return $collection; |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - return (bool)$return; |
|
| 305 | + return (bool) $return; |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -320,9 +320,9 @@ discard block |
||
| 320 | 320 | * due to performance issue on huge |
| 321 | 321 | * loop dispatching operations |
| 322 | 322 | */ |
| 323 | - if (!isset($this->itemInstances[ $item->getKey() ])) { |
|
| 324 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
| 325 | - } else if (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[ $item->getKey() ])) { |
|
| 323 | + if (!isset($this->itemInstances[$item->getKey()])) { |
|
| 324 | + $this->itemInstances[$item->getKey()] = $item; |
|
| 325 | + } else if (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
| 326 | 326 | throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); |
| 327 | 327 | } |
| 328 | 328 | |
@@ -374,8 +374,8 @@ discard block |
||
| 374 | 374 | public function saveDeferred(CacheItemInterface $item) |
| 375 | 375 | { |
| 376 | 376 | if (!\array_key_exists($item->getKey(), $this->itemInstances)) { |
| 377 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
| 378 | - } else if (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[ $item->getKey() ])) { |
|
| 377 | + $this->itemInstances[$item->getKey()] = $item; |
|
| 378 | + } else if (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
| 379 | 379 | throw new \RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.'); |
| 380 | 380 | } |
| 381 | 381 | |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | */ |
| 387 | 387 | $this->eventManager->dispatch('CacheSaveDeferredItem', $this, $item); |
| 388 | 388 | |
| 389 | - return $this->deferredList[ $item->getKey() ] = $item; |
|
| 389 | + return $this->deferredList[$item->getKey()] = $item; |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
@@ -406,11 +406,11 @@ discard block |
||
| 406 | 406 | foreach ($this->deferredList as $key => $item) { |
| 407 | 407 | $result = $this->save($item); |
| 408 | 408 | if ($return !== false) { |
| 409 | - unset($this->deferredList[ $key ]); |
|
| 409 | + unset($this->deferredList[$key]); |
|
| 410 | 410 | $return = $result; |
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - return (bool)$return; |
|
| 414 | + return (bool) $return; |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @author Georges.L (Geolim4) <[email protected]> |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -declare(strict_types=1); |
|
| 14 | +declare(strict_types = 1); |
|
| 15 | 15 | |
| 16 | 16 | namespace Phpfastcache\Core\Pool; |
| 17 | 17 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | public function getItemsAsJsonString(array $keys = [], $option = 0, $depth = 512): string |
| 38 | 38 | { |
| 39 | - $callback = function (CacheItemInterface $item) { |
|
| 39 | + $callback = function(CacheItemInterface $item) { |
|
| 40 | 40 | return $item->get(); |
| 41 | 41 | }; |
| 42 | 42 | return \json_encode(\array_map($callback, \array_values($this->getItems($keys))), $option, $depth); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | if (\is_string($tagName)) { |
| 51 | 51 | $driverResponse = $this->getItem($this->getTagKey($tagName)); |
| 52 | 52 | if ($driverResponse->isHit()) { |
| 53 | - $items = (array)$driverResponse->get(); |
|
| 53 | + $items = (array) $driverResponse->get(); |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * getItems() may provides expired item(s) |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * |
| 63 | 63 | * #headache |
| 64 | 64 | */ |
| 65 | - return \array_filter($this->getItems(\array_unique(\array_keys($items))), function (ExtendedCacheItemInterface $item) { |
|
| 65 | + return \array_filter($this->getItems(\array_unique(\array_keys($items))), function(ExtendedCacheItemInterface $item) { |
|
| 66 | 66 | return $item->isHit(); |
| 67 | 67 | }); |
| 68 | 68 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | foreach ($items as $key => $item) { |
| 101 | 101 | if (\array_diff($tagNames, $item->getTags())) { |
| 102 | - unset($items[ $key ]); |
|
| 102 | + unset($items[$key]); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | public function getItemsByTagsAsJsonString(array $tagNames, $option = 0, $depth = 512) |
| 114 | 114 | { |
| 115 | - $callback = function (CacheItemInterface $item) { |
|
| 115 | + $callback = function(CacheItemInterface $item) { |
|
| 116 | 116 | return $item->get(); |
| 117 | 117 | }; |
| 118 | 118 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | */ |
| 384 | 384 | public function detachItem(CacheItemInterface $item) |
| 385 | 385 | { |
| 386 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
| 386 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
| 387 | 387 | $this->deregisterItem($item); |
| 388 | 388 | } |
| 389 | 389 | } |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | */ |
| 404 | 404 | public function attachItem(CacheItemInterface $item) |
| 405 | 405 | { |
| 406 | - if (isset($this->itemInstances[ $item->getKey() ]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[ $item->getKey() ])) { |
|
| 406 | + if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) { |
|
| 407 | 407 | throw new PhpfastcacheLogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.'); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - $this->itemInstances[ $item->getKey() ] = $item; |
|
| 410 | + $this->itemInstances[$item->getKey()] = $item; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | |
@@ -419,10 +419,10 @@ discard block |
||
| 419 | 419 | protected function deregisterItem($item) |
| 420 | 420 | { |
| 421 | 421 | if ($item instanceof CacheItemInterface) { |
| 422 | - unset($this->itemInstances[ $item->getKey() ]); |
|
| 422 | + unset($this->itemInstances[$item->getKey()]); |
|
| 423 | 423 | |
| 424 | 424 | } else if (\is_string($item)) { |
| 425 | - unset($this->itemInstances[ $item ]); |
|
| 425 | + unset($this->itemInstances[$item]); |
|
| 426 | 426 | } else { |
| 427 | 427 | throw new PhpfastcacheInvalidArgumentException('Invalid type for $item variable'); |
| 428 | 428 | } |
@@ -449,8 +449,8 @@ discard block |
||
| 449 | 449 | */ |
| 450 | 450 | public function isAttached(CacheItemInterface $item) |
| 451 | 451 | { |
| 452 | - if (isset($this->itemInstances[ $item->getKey() ])) { |
|
| 453 | - return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[ $item->getKey() ]); |
|
| 452 | + if (isset($this->itemInstances[$item->getKey()])) { |
|
| 453 | + return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]); |
|
| 454 | 454 | } |
| 455 | 455 | return null; |
| 456 | 456 | } |
@@ -473,8 +473,8 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | public function saveMultiple(...$items): bool |
| 475 | 475 | { |
| 476 | - if (isset($items[ 0 ]) && \is_array($items[ 0 ])) { |
|
| 477 | - foreach ($items[ 0 ] as $item) { |
|
| 476 | + if (isset($items[0]) && \is_array($items[0])) { |
|
| 477 | + foreach ($items[0] as $item) { |
|
| 478 | 478 | $this->save($item); |
| 479 | 479 | } |
| 480 | 480 | return true; |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | protected static function cleanFileName($filename): string |
| 193 | 193 | { |
| 194 | 194 | $regex = [ |
| 195 | - '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', |
|
| 196 | - '/\.$/', |
|
| 197 | - '/^\./', |
|
| 195 | + '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/', |
|
| 196 | + '/\.$/', |
|
| 197 | + '/^\./', |
|
| 198 | 198 | ]; |
| 199 | 199 | $replace = ['-', '', '']; |
| 200 | 200 | |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | $tmpFilename = Directory::getAbsolutePath(\dirname($file) . '/tmp_' . \md5( |
| 291 | 291 | \str_shuffle(\uniqid($this->getDriverName(), false)) |
| 292 | 292 | . \str_shuffle(\uniqid($this->getDriverName(), false)) |
| 293 | - )); |
|
| 293 | + )); |
|
| 294 | 294 | |
| 295 | 295 | $f = \fopen($tmpFilename, 'w+'); |
| 296 | 296 | \flock($f, LOCK_EX); |
@@ -332,11 +332,11 @@ discard block |
||
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | $stat->setData(\implode(', ', \array_keys($this->itemInstances))) |
| 335 | - ->setRawData([ |
|
| 335 | + ->setRawData([ |
|
| 336 | 336 | 'tmp' => $this->tmp, |
| 337 | - ]) |
|
| 338 | - ->setSize(Directory::dirSize($path)) |
|
| 339 | - ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
| 337 | + ]) |
|
| 338 | + ->setSize(Directory::dirSize($path)) |
|
| 339 | + ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path)); |
|
| 340 | 340 | |
| 341 | 341 | return $stat; |
| 342 | 342 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @author Georges.L (Geolim4) <[email protected]> |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -declare(strict_types=1); |
|
| 14 | +declare(strict_types = 1); |
|
| 15 | 15 | |
| 16 | 16 | namespace Phpfastcache\Util; |
| 17 | 17 | |
@@ -87,8 +87,7 @@ discard block |
||
| 87 | 87 | return \unlink($source); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $files = new RecursiveIteratorIterator |
|
| 91 | - ( |
|
| 90 | + $files = new RecursiveIteratorIterator( |
|
| 92 | 91 | new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), |
| 93 | 92 | RecursiveIteratorIterator::CHILD_FIRST |
| 94 | 93 | ); |
@@ -138,8 +137,8 @@ discard block |
||
| 138 | 137 | /** |
| 139 | 138 | * Allows to dereference char |
| 140 | 139 | */ |
| 141 | - $__FILE__ = \preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__);// remove file protocols such as "phar://" etc. |
|
| 142 | - $prefix = $__FILE__[ 0 ] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''; |
|
| 140 | + $__FILE__ = \preg_replace('~^(([a-z0-9\-]+)://)~', '', __FILE__); // remove file protocols such as "phar://" etc. |
|
| 141 | + $prefix = $__FILE__[0] === DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : ''; |
|
| 143 | 142 | return $prefix . \implode(DIRECTORY_SEPARATOR, $absolutes); |
| 144 | 143 | } |
| 145 | 144 | } |
| 146 | 145 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @author Georges.L (Geolim4) <[email protected]> |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -declare(strict_types=1); |
|
| 14 | +declare(strict_types = 1); |
|
| 15 | 15 | |
| 16 | 16 | namespace Phpfastcache\Util; |
| 17 | 17 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | } |
| 56 | 56 | $map = []; |
| 57 | 57 | |
| 58 | - if(\is_array($dir) || $dir instanceof \Traversable){ |
|
| 58 | + if (\is_array($dir) || $dir instanceof \Traversable) { |
|
| 59 | 59 | foreach ($dir as $file) { |
| 60 | 60 | if (!$file->isFile()) { |
| 61 | 61 | continue; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | \gc_mem_caches(); |
| 71 | 71 | } |
| 72 | 72 | foreach ($classes as $class) { |
| 73 | - $map[ $class ] = $path; |
|
| 73 | + $map[$class] = $path; |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | } |
@@ -94,19 +94,19 @@ discard block |
||
| 94 | 94 | $tokens = \token_get_all($contents); |
| 95 | 95 | $classes = []; |
| 96 | 96 | $namespace = ''; |
| 97 | - for ($i = 0; isset($tokens[ $i ]); ++$i) { |
|
| 98 | - $token = $tokens[ $i ]; |
|
| 99 | - if (!isset($token[ 1 ])) { |
|
| 97 | + for ($i = 0; isset($tokens[$i]); ++$i) { |
|
| 98 | + $token = $tokens[$i]; |
|
| 99 | + if (!isset($token[1])) { |
|
| 100 | 100 | continue; |
| 101 | 101 | } |
| 102 | 102 | $class = ''; |
| 103 | - switch ($token[ 0 ]) { |
|
| 103 | + switch ($token[0]) { |
|
| 104 | 104 | case T_NAMESPACE: |
| 105 | 105 | $namespace = ''; |
| 106 | 106 | // If there is a namespace, extract it |
| 107 | - while (isset($tokens[ ++$i ][ 1 ])) { |
|
| 108 | - if (\in_array($tokens[ $i ][ 0 ], [T_STRING, T_NS_SEPARATOR])) { |
|
| 109 | - $namespace .= $tokens[ $i ][ 1 ]; |
|
| 107 | + while (isset($tokens[ ++$i][1])) { |
|
| 108 | + if (\in_array($tokens[$i][0], [T_STRING, T_NS_SEPARATOR])) { |
|
| 109 | + $namespace .= $tokens[$i][1]; |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | $namespace .= '\\'; |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | // Skip usage of ::class constant |
| 118 | 118 | $isClassConstant = false; |
| 119 | 119 | for ($j = $i - 1; $j > 0; --$j) { |
| 120 | - if (!isset($tokens[ $j ][ 1 ])) { |
|
| 120 | + if (!isset($tokens[$j][1])) { |
|
| 121 | 121 | break; |
| 122 | 122 | } |
| 123 | - if (T_DOUBLE_COLON === $tokens[ $j ][ 0 ]) { |
|
| 123 | + if (T_DOUBLE_COLON === $tokens[$j][0]) { |
|
| 124 | 124 | $isClassConstant = true; |
| 125 | 125 | break; |
| 126 | - } elseif (!\in_array($tokens[ $j ][ 0 ], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
| 126 | + } elseif (!\in_array($tokens[$j][0], [T_WHITESPACE, T_DOC_COMMENT, T_COMMENT], false)) { |
|
| 127 | 127 | break; |
| 128 | 128 | } |
| 129 | 129 | } |
@@ -131,11 +131,11 @@ discard block |
||
| 131 | 131 | break; |
| 132 | 132 | } |
| 133 | 133 | // Find the classname |
| 134 | - while (isset($tokens[ ++$i ][ 1 ])) { |
|
| 135 | - $t = $tokens[ $i ]; |
|
| 136 | - if (T_STRING === $t[ 0 ]) { |
|
| 137 | - $class .= $t[ 1 ]; |
|
| 138 | - } elseif ('' !== $class && T_WHITESPACE === $t[ 0 ]) { |
|
| 134 | + while (isset($tokens[ ++$i][1])) { |
|
| 135 | + $t = $tokens[$i]; |
|
| 136 | + if (T_STRING === $t[0]) { |
|
| 137 | + $class .= $t[1]; |
|
| 138 | + } elseif ('' !== $class && T_WHITESPACE === $t[0]) { |
|
| 139 | 139 | break; |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | return true; |
| 42 | 42 | } else if (\constant($CONSTANT_NAME) !== $driverName) { |
| 43 | 43 | trigger_error('Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours', |
| 44 | - E_USER_WARNING); |
|
| 44 | + E_USER_WARNING); |
|
| 45 | 45 | |
| 46 | 46 | return false; |
| 47 | 47 | } |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | if(array_diff_key($array, get_object_vars($this))){ |
| 102 | 102 | throw new PhpfastcacheInvalidConfigurationException(\sprintf( |
| 103 | - 'Invalid option(s) for the config %s: %s', |
|
| 104 | - static::class, |
|
| 105 | - implode(', ', array_keys(array_diff_key($array, get_object_vars($this)))) |
|
| 103 | + 'Invalid option(s) for the config %s: %s', |
|
| 104 | + static::class, |
|
| 105 | + implode(', ', array_keys(array_diff_key($array, get_object_vars($this)))) |
|
| 106 | 106 | )); |
| 107 | 107 | } |
| 108 | 108 | |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | $typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($parameter->getType() === 'object' ? $parameter->getClass() : $parameter->getType()) : 'Unknown type'); |
| 135 | 135 | |
| 136 | 136 | throw new PhpfastcacheInvalidConfigurationException(\sprintf( |
| 137 | - 'Invalid type hint found for "%s", expected "%s" got "%s"', |
|
| 138 | - lcfirst(substr($method, 3)), |
|
| 139 | - $typeHintExpected, |
|
| 140 | - $typeHintGot |
|
| 137 | + 'Invalid type hint found for "%s", expected "%s" got "%s"', |
|
| 138 | + lcfirst(substr($method, 3)), |
|
| 139 | + $typeHintExpected, |
|
| 140 | + $typeHintGot |
|
| 141 | 141 | )); |
| 142 | 142 | } |
| 143 | 143 | } |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | { |
| 332 | 332 | if($fallbackConfig !== null && !($fallbackConfig instanceof self)){ |
| 333 | 333 | throw new PhpfastcacheInvalidArgumentException(\sprintf( |
| 334 | - 'Invalid argument "%s" for %s', |
|
| 335 | - gettype($fallbackConfig) === 'object' ? get_class($fallbackConfig) : gettype($fallbackConfig), |
|
| 336 | - __METHOD__ |
|
| 334 | + 'Invalid argument "%s" for %s', |
|
| 335 | + gettype($fallbackConfig) === 'object' ? get_class($fallbackConfig) : gettype($fallbackConfig), |
|
| 336 | + __METHOD__ |
|
| 337 | 337 | )); |
| 338 | 338 | } |
| 339 | 339 | $this->fallbackConfig = $fallbackConfig; |
@@ -432,10 +432,10 @@ discard block |
||
| 432 | 432 | * by opening a pull request :) |
| 433 | 433 | */ |
| 434 | 434 | static $safeFileExtensions = [ |
| 435 | - 'txt', |
|
| 436 | - 'cache', |
|
| 437 | - 'db', |
|
| 438 | - 'pfc', |
|
| 435 | + 'txt', |
|
| 436 | + 'cache', |
|
| 437 | + 'db', |
|
| 438 | + 'pfc', |
|
| 439 | 439 | ]; |
| 440 | 440 | |
| 441 | 441 | if (\strpos($cacheFileExtension, '.') !== false) { |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | } |
| 444 | 444 | if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) { |
| 445 | 445 | throw new PhpfastcacheInvalidConfigurationException( |
| 446 | - "{$cacheFileExtension} is not a safe extension, currently allowed extension: " . \implode(', ', $safeFileExtensions) |
|
| 446 | + "{$cacheFileExtension} is not a safe extension, currently allowed extension: " . \implode(', ', $safeFileExtensions) |
|
| 447 | 447 | ); |
| 448 | 448 | } |
| 449 | 449 | |
@@ -92,33 +92,33 @@ discard block |
||
| 92 | 92 | public function __construct(...$args) |
| 93 | 93 | { |
| 94 | 94 | parent::__construct(...$args); |
| 95 | - $array =& $this->getArray(); |
|
| 95 | + $array = & $this->getArray(); |
|
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Detect unwanted keys and throw an exception. |
| 99 | 99 | * No more kidding now, it's 21th century. |
| 100 | 100 | */ |
| 101 | - if(array_diff_key($array, get_object_vars($this))){ |
|
| 101 | + if (array_diff_key($array, get_object_vars($this))) { |
|
| 102 | 102 | throw new PhpfastcacheInvalidConfigurationException(\sprintf( |
| 103 | 103 | 'Invalid option(s) for the config %s: %s', |
| 104 | 104 | static::class, |
| 105 | - implode(', ', array_keys(array_diff_key($array, get_object_vars($this)))) |
|
| 105 | + implode(', ', array_keys(array_diff_key($array, get_object_vars($this)))) |
|
| 106 | 106 | )); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | foreach (get_object_vars($this) as $property => $value) { |
| 110 | 110 | |
| 111 | - if(array_key_exists($property, $array)){ |
|
| 112 | - $this->$property = &$array[ $property ]; |
|
| 113 | - }else{ |
|
| 114 | - $array[ $property ] = &$this->$property; |
|
| 111 | + if (array_key_exists($property, $array)) { |
|
| 112 | + $this->$property = &$array[$property]; |
|
| 113 | + } else { |
|
| 114 | + $array[$property] = &$this->$property; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | foreach (get_class_methods($this) as $method) { |
| 119 | - if(strpos($method, 'set') === 0){ |
|
| 119 | + if (strpos($method, 'set') === 0) { |
|
| 120 | 120 | $value = null; |
| 121 | - try{ |
|
| 121 | + try { |
|
| 122 | 122 | /** |
| 123 | 123 | * We use property instead of getter |
| 124 | 124 | * because of is/get conditions and |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | $value = $this->{lcfirst(substr($method, 3))}; |
| 129 | 129 | $this->{$method}($value); |
| 130 | - }catch(\TypeError $e){ |
|
| 130 | + } catch (\TypeError $e) { |
|
| 131 | 131 | $typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value); |
| 132 | 132 | $reflectionMethod = new \ReflectionMethod($this, $method); |
| 133 | 133 | $parameter = $reflectionMethod->getParameters()[0] ?? null; |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function setIgnoreSymfonyNotice(bool $ignoreSymfonyNotice): self |
| 216 | 216 | { |
| 217 | - if($ignoreSymfonyNotice){ |
|
| 217 | + if ($ignoreSymfonyNotice) { |
|
| 218 | 218 | trigger_error('Configuration option "ignoreSymfonyNotice" is deprecated as of the V7', E_USER_DEPRECATED); |
| 219 | 219 | } |
| 220 | 220 | $this->ignoreSymfonyNotice = $ignoreSymfonyNotice; |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | */ |
| 330 | 330 | public function setFallbackConfig($fallbackConfig): self |
| 331 | 331 | { |
| 332 | - if($fallbackConfig !== null && !($fallbackConfig instanceof self)){ |
|
| 332 | + if ($fallbackConfig !== null && !($fallbackConfig instanceof self)) { |
|
| 333 | 333 | throw new PhpfastcacheInvalidArgumentException(\sprintf( |
| 334 | 334 | 'Invalid argument "%s" for %s', |
| 335 | 335 | gettype($fallbackConfig) === 'object' ? get_class($fallbackConfig) : gettype($fallbackConfig), |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | use LogicException; |
| 20 | 20 | use MongoDB\{ |
| 21 | - BSON\Binary, BSON\UTCDateTime, Collection, DeleteResult, Driver\Command, Driver\Exception\Exception as MongoDBException, Driver\Manager as MongodbManager |
|
| 21 | + BSON\Binary, BSON\UTCDateTime, Collection, DeleteResult, Driver\Command, Driver\Exception\Exception as MongoDBException, Driver\Manager as MongodbManager |
|
| 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 | use Phpfastcache\Util\ArrayObject; |
| 31 | 31 | use Psr\Cache\CacheItemInterface; |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | if ($document) { |
| 73 | 73 | $return = [ |
| 74 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
| 75 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
| 76 | - self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
| 74 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
| 75 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
| 76 | + self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
| 77 | 77 | ]; |
| 78 | 78 | |
| 79 | 79 | if(!empty($this->getConfigOption('itemDetailedDate'))){ |
| 80 | 80 | $return += [ |
| 81 | - self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime() |
|
| 81 | + self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime() |
|
| 82 | 82 | ->getTimestamp()), |
| 83 | - self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime() |
|
| 83 | + self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime() |
|
| 84 | 84 | ->getTimestamp()), |
| 85 | 85 | ]; |
| 86 | 86 | } |
@@ -105,23 +105,23 @@ discard block |
||
| 105 | 105 | if ($item instanceof Item) { |
| 106 | 106 | try { |
| 107 | 107 | $set = [ |
| 108 | - self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
| 109 | - self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
| 110 | - self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((\time() + $item->getTtl()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
| 108 | + self::DRIVER_DATA_WRAPPER_INDEX => new Binary($this->encode($item->get()), Binary::TYPE_GENERIC), |
|
| 109 | + self::DRIVER_TAGS_WRAPPER_INDEX => new Binary($this->encode($item->getTags()), Binary::TYPE_GENERIC), |
|
| 110 | + self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((\time() + $item->getTtl()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
| 111 | 111 | ]; |
| 112 | 112 | |
| 113 | 113 | if(!empty($this->getConfigOption('itemDetailedDate'))){ |
| 114 | 114 | $set += [ |
| 115 | - self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
| 116 | - self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
| 115 | + self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
| 116 | + self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
|
| 117 | 117 | ]; |
| 118 | 118 | } |
| 119 | 119 | $result = (array)$this->getCollection()->updateOne( |
| 120 | - ['_id' => $item->getEncodedKey()], |
|
| 121 | - [ |
|
| 120 | + ['_id' => $item->getEncodedKey()], |
|
| 121 | + [ |
|
| 122 | 122 | '$set' => $set, |
| 123 | - ], |
|
| 124 | - ['upsert' => true, 'multiple' => false] |
|
| 123 | + ], |
|
| 124 | + ['upsert' => true, 'multiple' => false] |
|
| 125 | 125 | ); |
| 126 | 126 | } catch (MongoDBException $e) { |
| 127 | 127 | throw new PhpfastcacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | * @todo make an url builder |
| 192 | 192 | */ |
| 193 | 193 | $this->instance = $this->instance ?: (new MongodbManager('mongodb://' . |
| 194 | - ($clientConfig[ 'username' ] ?: '') . |
|
| 195 | - ($clientConfig[ 'password' ] ? ":{$clientConfig['password']}" : '') . |
|
| 196 | - ($clientConfig[ 'username' ] ? '@' : '') . "{$clientConfig['host']}" . |
|
| 197 | - ($clientConfig[ 'port' ] != 27017 ? ":{$clientConfig['port']}" : ''), ['connectTimeoutMS' => $clientConfig[ 'timeout' ] * 1000])); |
|
| 194 | + ($clientConfig[ 'username' ] ?: '') . |
|
| 195 | + ($clientConfig[ 'password' ] ? ":{$clientConfig['password']}" : '') . |
|
| 196 | + ($clientConfig[ 'username' ] ? '@' : '') . "{$clientConfig['host']}" . |
|
| 197 | + ($clientConfig[ 'port' ] != 27017 ? ":{$clientConfig['port']}" : ''), ['connectTimeoutMS' => $clientConfig[ 'timeout' ] * 1000])); |
|
| 198 | 198 | $this->collection = $this->collection ?: new Collection($this->instance, $clientConfig[ 'databaseName' ], $clientConfig[ 'collectionName' ]); |
| 199 | 199 | |
| 200 | 200 | return true; |
@@ -221,15 +221,15 @@ discard block |
||
| 221 | 221 | public function getStats(): DriverStatistic |
| 222 | 222 | { |
| 223 | 223 | $serverStats = $this->instance->executeCommand($this->getConfigOption('databaseName'), new Command([ |
| 224 | - 'serverStatus' => 1, |
|
| 225 | - 'recordStats' => 0, |
|
| 226 | - 'repl' => 0, |
|
| 227 | - 'metrics' => 0, |
|
| 224 | + 'serverStatus' => 1, |
|
| 225 | + 'recordStats' => 0, |
|
| 226 | + 'repl' => 0, |
|
| 227 | + 'metrics' => 0, |
|
| 228 | 228 | ]))->toArray()[ 0 ]; |
| 229 | 229 | |
| 230 | 230 | $collectionStats = $this->instance->executeCommand($this->getConfigOption('databaseName'), new Command([ |
| 231 | - 'collStats' => ($this->config->getOption('collectionName') !== null ? $this->config->getOption('collectionName') : 'Cache'), |
|
| 232 | - 'verbose' => true, |
|
| 231 | + 'collStats' => ($this->config->getOption('collectionName') !== null ? $this->config->getOption('collectionName') : 'Cache'), |
|
| 232 | + 'verbose' => true, |
|
| 233 | 233 | ]))->toArray()[ 0 ]; |
| 234 | 234 | |
| 235 | 235 | $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { |
@@ -258,14 +258,14 @@ discard block |
||
| 258 | 258 | $collectionStats = $array_filter_recursive($collectionStats, $callback); |
| 259 | 259 | |
| 260 | 260 | $stats = (new DriverStatistic()) |
| 261 | - ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400, |
|
| 262 | - 1) . "\n For more information see RawData.") |
|
| 263 | - ->setSize($collectionStats->size) |
|
| 264 | - ->setData(\implode(', ', \array_keys($this->itemInstances))) |
|
| 265 | - ->setRawData([ |
|
| 261 | + ->setInfo('MongoDB version ' . $serverStats->version . ', Uptime (in days): ' . round($serverStats->uptime / 86400, |
|
| 262 | + 1) . "\n For more information see RawData.") |
|
| 263 | + ->setSize($collectionStats->size) |
|
| 264 | + ->setData(\implode(', ', \array_keys($this->itemInstances))) |
|
| 265 | + ->setRawData([ |
|
| 266 | 266 | 'serverStatus' => $serverStats, |
| 267 | 267 | 'collStats' => $collectionStats, |
| 268 | - ]); |
|
| 268 | + ]); |
|
| 269 | 269 | |
| 270 | 270 | return $stats; |
| 271 | 271 | } |
@@ -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 | |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | if ($document) { |
| 73 | 73 | $return = [ |
| 74 | - self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_DATA_WRAPPER_INDEX ]->getData()), |
|
| 75 | - self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[ self::DRIVER_TAGS_WRAPPER_INDEX ]->getData()), |
|
| 76 | - self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_EDATE_WRAPPER_INDEX ]->toDateTime()->getTimestamp()), |
|
| 74 | + self::DRIVER_DATA_WRAPPER_INDEX => $this->decode($document[self::DRIVER_DATA_WRAPPER_INDEX]->getData()), |
|
| 75 | + self::DRIVER_TAGS_WRAPPER_INDEX => $this->decode($document[self::DRIVER_TAGS_WRAPPER_INDEX]->getData()), |
|
| 76 | + self::DRIVER_EDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_EDATE_WRAPPER_INDEX]->toDateTime()->getTimestamp()), |
|
| 77 | 77 | ]; |
| 78 | 78 | |
| 79 | - if(!empty($this->getConfigOption('itemDetailedDate'))){ |
|
| 79 | + if (!empty($this->getConfigOption('itemDetailedDate'))) { |
|
| 80 | 80 | $return += [ |
| 81 | - self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_MDATE_WRAPPER_INDEX ]->toDateTime() |
|
| 81 | + self::DRIVER_MDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_MDATE_WRAPPER_INDEX]->toDateTime() |
|
| 82 | 82 | ->getTimestamp()), |
| 83 | - self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[ self::DRIVER_CDATE_WRAPPER_INDEX ]->toDateTime() |
|
| 83 | + self::DRIVER_CDATE_WRAPPER_INDEX => (new \DateTime())->setTimestamp($document[self::DRIVER_CDATE_WRAPPER_INDEX]->toDateTime() |
|
| 84 | 84 | ->getTimestamp()), |
| 85 | 85 | ]; |
| 86 | 86 | } |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | self::DRIVER_EDATE_WRAPPER_INDEX => ($item->getTtl() > 0 ? new UTCDateTime((\time() + $item->getTtl()) * 1000) : new UTCDateTime(\time() * 1000)), |
| 111 | 111 | ]; |
| 112 | 112 | |
| 113 | - if(!empty($this->getConfigOption('itemDetailedDate'))){ |
|
| 113 | + if (!empty($this->getConfigOption('itemDetailedDate'))) { |
|
| 114 | 114 | $set += [ |
| 115 | 115 | self::DRIVER_MDATE_WRAPPER_INDEX => ($item->getModificationDate() ? new UTCDateTime(($item->getModificationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
| 116 | 116 | self::DRIVER_CDATE_WRAPPER_INDEX => ($item->getCreationDate() ? new UTCDateTime(($item->getCreationDate()->getTimestamp()) * 1000) : new UTCDateTime(\time() * 1000)), |
| 117 | 117 | ]; |
| 118 | 118 | } |
| 119 | - $result = (array)$this->getCollection()->updateOne( |
|
| 119 | + $result = (array) $this->getCollection()->updateOne( |
|
| 120 | 120 | ['_id' => $item->getEncodedKey()], |
| 121 | 121 | [ |
| 122 | 122 | '$set' => $set, |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | throw new PhpfastcacheDriverException('Got an exception while trying to write data to MongoDB server', null, $e); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - return isset($result[ 'ok' ]) ? $result[ 'ok' ] == 1 : true; |
|
| 130 | + return isset($result['ok']) ? $result['ok'] == 1 : true; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | $this->save($this->getItem('__PFC_CACHE_CLEARED__')->set(true)); |
| 173 | 173 | |
| 174 | - return !empty($result[ 'ok' ]); |
|
| 174 | + return !empty($result['ok']); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | * @todo make an url builder |
| 192 | 192 | */ |
| 193 | 193 | $this->instance = $this->instance ?: (new MongodbManager('mongodb://' . |
| 194 | - ($clientConfig[ 'username' ] ?: '') . |
|
| 195 | - ($clientConfig[ 'password' ] ? ":{$clientConfig['password']}" : '') . |
|
| 196 | - ($clientConfig[ 'username' ] ? '@' : '') . "{$clientConfig['host']}" . |
|
| 197 | - ($clientConfig[ 'port' ] != 27017 ? ":{$clientConfig['port']}" : ''), ['connectTimeoutMS' => $clientConfig[ 'timeout' ] * 1000])); |
|
| 198 | - $this->collection = $this->collection ?: new Collection($this->instance, $clientConfig[ 'databaseName' ], $clientConfig[ 'collectionName' ]); |
|
| 194 | + ($clientConfig['username'] ?: '') . |
|
| 195 | + ($clientConfig['password'] ? ":{$clientConfig['password']}" : '') . |
|
| 196 | + ($clientConfig['username'] ? '@' : '') . "{$clientConfig['host']}" . |
|
| 197 | + ($clientConfig['port'] != 27017 ? ":{$clientConfig['port']}" : ''), ['connectTimeoutMS' => $clientConfig['timeout'] * 1000])); |
|
| 198 | + $this->collection = $this->collection ?: new Collection($this->instance, $clientConfig['databaseName'], $clientConfig['collectionName']); |
|
| 199 | 199 | |
| 200 | 200 | return true; |
| 201 | 201 | } |
@@ -225,14 +225,14 @@ discard block |
||
| 225 | 225 | 'recordStats' => 0, |
| 226 | 226 | 'repl' => 0, |
| 227 | 227 | 'metrics' => 0, |
| 228 | - ]))->toArray()[ 0 ]; |
|
| 228 | + ]))->toArray()[0]; |
|
| 229 | 229 | |
| 230 | 230 | $collectionStats = $this->instance->executeCommand($this->getConfigOption('databaseName'), new Command([ |
| 231 | 231 | 'collStats' => ($this->config->getOption('collectionName') !== null ? $this->config->getOption('collectionName') : 'Cache'), |
| 232 | 232 | 'verbose' => true, |
| 233 | - ]))->toArray()[ 0 ]; |
|
| 233 | + ]))->toArray()[0]; |
|
| 234 | 234 | |
| 235 | - $array_filter_recursive = function ($array, callable $callback = null) use (&$array_filter_recursive) { |
|
| 235 | + $array_filter_recursive = function($array, callable $callback = null) use (&$array_filter_recursive) { |
|
| 236 | 236 | $array = $callback($array); |
| 237 | 237 | |
| 238 | 238 | if (\is_object($array) || \is_array($array)) { |
@@ -244,12 +244,12 @@ discard block |
||
| 244 | 244 | return $array; |
| 245 | 245 | }; |
| 246 | 246 | |
| 247 | - $callback = function ($item) { |
|
| 247 | + $callback = function($item) { |
|
| 248 | 248 | /** |
| 249 | 249 | * Remove unserializable properties |
| 250 | 250 | */ |
| 251 | 251 | if ($item instanceof \MongoDB\BSON\UTCDateTime) { |
| 252 | - return (string)$item; |
|
| 252 | + return (string) $item; |
|
| 253 | 253 | } |
| 254 | 254 | return $item; |
| 255 | 255 | }; |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | use PDOException; |
| 20 | 20 | use Phpfastcache\Core\Pool\{DriverBaseTrait, ExtendedCacheItemPoolInterface, IO\IOHelperTrait}; |
| 21 | 21 | use Phpfastcache\Exceptions\{ |
| 22 | - PhpfastcacheInvalidArgumentException, PhpfastcacheIOException |
|
| 22 | + PhpfastcacheInvalidArgumentException, PhpfastcacheIOException |
|
| 23 | 23 | }; |
| 24 | 24 | use Psr\Cache\CacheItemInterface; |
| 25 | 25 | |
@@ -108,18 +108,18 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | try { |
| 110 | 110 | $stm = $this->getDb($item->getKey()) |
| 111 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 111 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 112 | 112 | $stm->execute([ |
| 113 | - ':keyword' => $item->getKey(), |
|
| 113 | + ':keyword' => $item->getKey(), |
|
| 114 | 114 | ]); |
| 115 | 115 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 116 | 116 | |
| 117 | 117 | } catch (PDOException $e) { |
| 118 | 118 | try { |
| 119 | 119 | $stm = $this->getDb($item->getKey(), true) |
| 120 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 120 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
| 121 | 121 | $stm->execute([ |
| 122 | - ':keyword' => $item->getKey(), |
|
| 122 | + ':keyword' => $item->getKey(), |
|
| 123 | 123 | ]); |
| 124 | 124 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 125 | 125 | } catch (PDOException $e) { |
@@ -162,11 +162,11 @@ discard block |
||
| 162 | 162 | if ($toWrite == true) { |
| 163 | 163 | try { |
| 164 | 164 | $stm = $this->getDb($item->getKey()) |
| 165 | - ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 165 | + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 166 | 166 | $stm->execute([ |
| 167 | - ':keyword' => $item->getKey(), |
|
| 168 | - ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 169 | - ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
| 167 | + ':keyword' => $item->getKey(), |
|
| 168 | + ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 169 | + ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
| 170 | 170 | ]); |
| 171 | 171 | |
| 172 | 172 | return true; |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | try { |
| 176 | 176 | $stm = $this->getDb($item->getKey(), true) |
| 177 | - ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 177 | + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
| 178 | 178 | $stm->execute([ |
| 179 | - ':keyword' => $item->getKey(), |
|
| 180 | - ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 181 | - ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
| 179 | + ':keyword' => $item->getKey(), |
|
| 180 | + ':object' => $this->encode($this->driverPreWrap($item)), |
|
| 181 | + ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
| 182 | 182 | ]); |
| 183 | 183 | } catch (PDOException $e) { |
| 184 | 184 | return false; |
@@ -205,11 +205,11 @@ discard block |
||
| 205 | 205 | if ($item instanceof Item) { |
| 206 | 206 | try { |
| 207 | 207 | $stm = $this->getDb($item->getKey()) |
| 208 | - ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); |
|
| 208 | + ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); |
|
| 209 | 209 | |
| 210 | 210 | return $stm->execute([ |
| 211 | - ':keyword' => $item->getKey(), |
|
| 212 | - ':U' => \time(), |
|
| 211 | + ':keyword' => $item->getKey(), |
|
| 212 | + ':U' => \time(), |
|
| 213 | 213 | ]); |
| 214 | 214 | } catch (PDOException $e) { |
| 215 | 215 | return false; |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | $PDO = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE); |
| 291 | 291 | $PDO->setAttribute(PDO::ATTR_ERRMODE, |
| 292 | - PDO::ERRMODE_EXCEPTION); |
|
| 292 | + PDO::ERRMODE_EXCEPTION); |
|
| 293 | 293 | |
| 294 | 294 | if ($createTable == true) { |
| 295 | 295 | $this->initIndexing($PDO); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | // look for keyword |
| 325 | 325 | $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); |
| 326 | 326 | $stm->execute([ |
| 327 | - ':keyword' => $keyword, |
|
| 327 | + ':keyword' => $keyword, |
|
| 328 | 328 | ]); |
| 329 | 329 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
| 330 | 330 | if (isset($row[ 'db' ]) && $row[ 'db' ] != '') { |
@@ -336,8 +336,8 @@ discard block |
||
| 336 | 336 | $db = $this->currentDB; |
| 337 | 337 | $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); |
| 338 | 338 | $stm->execute([ |
| 339 | - ':keyword' => $keyword, |
|
| 340 | - ':db' => $db, |
|
| 339 | + ':keyword' => $keyword, |
|
| 340 | + ':db' => $db, |
|
| 341 | 341 | ]); |
| 342 | 342 | } |
| 343 | 343 | |