@@ -21,137 +21,137 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Config extends ConfigurationOption |
| 23 | 23 | { |
| 24 | - protected const DEFAULT_VALUE = '_default'; |
|
| 25 | - protected string $host = '127.0.0.1'; |
|
| 26 | - protected int $port = 8091; |
|
| 24 | + protected const DEFAULT_VALUE = '_default'; |
|
| 25 | + protected string $host = '127.0.0.1'; |
|
| 26 | + protected int $port = 8091; |
|
| 27 | 27 | // SSL: 18091 |
| 28 | 28 | |
| 29 | - protected string $username = ''; |
|
| 30 | - protected string $password = ''; |
|
| 31 | - protected string $bucketName = self::DEFAULT_VALUE; |
|
| 32 | - protected string $scopeName = self::DEFAULT_VALUE; |
|
| 33 | - protected string $collectionName = self::DEFAULT_VALUE; |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - public function getHost(): string |
|
| 37 | - { |
|
| 38 | - return $this->host; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param string $host |
|
| 43 | - * @return Config |
|
| 44 | - * @throws PhpfastcacheLogicException |
|
| 45 | - */ |
|
| 46 | - public function setHost(string $host): Config |
|
| 47 | - { |
|
| 48 | - return $this->setProperty('host', $host); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @return int |
|
| 53 | - */ |
|
| 54 | - public function getPort() |
|
| 55 | - { |
|
| 56 | - return $this->port; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param int $port |
|
| 61 | - * @return Config |
|
| 62 | - * @throws PhpfastcacheLogicException |
|
| 63 | - */ |
|
| 64 | - public function setPort(int $port): Config |
|
| 65 | - { |
|
| 66 | - return $this->setProperty('port', $port); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public function getUsername(): string |
|
| 73 | - { |
|
| 74 | - return $this->username; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $username |
|
| 79 | - * @return Config |
|
| 80 | - * @throws PhpfastcacheLogicException |
|
| 81 | - */ |
|
| 82 | - public function setUsername(string $username): Config |
|
| 83 | - { |
|
| 84 | - return $this->setProperty('username', $username); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function getPassword(): string |
|
| 91 | - { |
|
| 92 | - return $this->password; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @param string $password |
|
| 97 | - * @return Config |
|
| 98 | - * @throws PhpfastcacheLogicException |
|
| 99 | - */ |
|
| 100 | - public function setPassword(string $password): Config |
|
| 101 | - { |
|
| 102 | - return $this->setProperty('password', $password); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function getBucketName(): string |
|
| 109 | - { |
|
| 110 | - return $this->bucketName; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param string $bucketName |
|
| 115 | - * @return Config |
|
| 116 | - * @throws PhpfastcacheLogicException |
|
| 117 | - */ |
|
| 118 | - public function setBucketName(string $bucketName): Config |
|
| 119 | - { |
|
| 120 | - return $this->setProperty('bucketName', $bucketName); |
|
| 121 | - } |
|
| 122 | - /** |
|
| 123 | - * @return string |
|
| 124 | - */ |
|
| 125 | - public function getScopeName(): string |
|
| 126 | - { |
|
| 127 | - return $this->scopeName; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @param string $scopeName |
|
| 132 | - * @return Config |
|
| 133 | - * @throws PhpfastcacheLogicException |
|
| 134 | - */ |
|
| 135 | - public function setScopeName(string $scopeName): Config |
|
| 136 | - { |
|
| 137 | - return $this->setProperty('scopeName', $scopeName); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public function getCollectionName(): string |
|
| 144 | - { |
|
| 145 | - return $this->collectionName; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param string $collectionName |
|
| 150 | - * @return Config |
|
| 151 | - * @throws PhpfastcacheLogicException |
|
| 152 | - */ |
|
| 153 | - public function setCollectionName(string $collectionName): Config |
|
| 154 | - { |
|
| 155 | - return $this->setProperty('collectionName', $collectionName); |
|
| 156 | - } |
|
| 29 | + protected string $username = ''; |
|
| 30 | + protected string $password = ''; |
|
| 31 | + protected string $bucketName = self::DEFAULT_VALUE; |
|
| 32 | + protected string $scopeName = self::DEFAULT_VALUE; |
|
| 33 | + protected string $collectionName = self::DEFAULT_VALUE; |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + public function getHost(): string |
|
| 37 | + { |
|
| 38 | + return $this->host; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param string $host |
|
| 43 | + * @return Config |
|
| 44 | + * @throws PhpfastcacheLogicException |
|
| 45 | + */ |
|
| 46 | + public function setHost(string $host): Config |
|
| 47 | + { |
|
| 48 | + return $this->setProperty('host', $host); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @return int |
|
| 53 | + */ |
|
| 54 | + public function getPort() |
|
| 55 | + { |
|
| 56 | + return $this->port; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param int $port |
|
| 61 | + * @return Config |
|
| 62 | + * @throws PhpfastcacheLogicException |
|
| 63 | + */ |
|
| 64 | + public function setPort(int $port): Config |
|
| 65 | + { |
|
| 66 | + return $this->setProperty('port', $port); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public function getUsername(): string |
|
| 73 | + { |
|
| 74 | + return $this->username; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $username |
|
| 79 | + * @return Config |
|
| 80 | + * @throws PhpfastcacheLogicException |
|
| 81 | + */ |
|
| 82 | + public function setUsername(string $username): Config |
|
| 83 | + { |
|
| 84 | + return $this->setProperty('username', $username); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function getPassword(): string |
|
| 91 | + { |
|
| 92 | + return $this->password; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @param string $password |
|
| 97 | + * @return Config |
|
| 98 | + * @throws PhpfastcacheLogicException |
|
| 99 | + */ |
|
| 100 | + public function setPassword(string $password): Config |
|
| 101 | + { |
|
| 102 | + return $this->setProperty('password', $password); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function getBucketName(): string |
|
| 109 | + { |
|
| 110 | + return $this->bucketName; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param string $bucketName |
|
| 115 | + * @return Config |
|
| 116 | + * @throws PhpfastcacheLogicException |
|
| 117 | + */ |
|
| 118 | + public function setBucketName(string $bucketName): Config |
|
| 119 | + { |
|
| 120 | + return $this->setProperty('bucketName', $bucketName); |
|
| 121 | + } |
|
| 122 | + /** |
|
| 123 | + * @return string |
|
| 124 | + */ |
|
| 125 | + public function getScopeName(): string |
|
| 126 | + { |
|
| 127 | + return $this->scopeName; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @param string $scopeName |
|
| 132 | + * @return Config |
|
| 133 | + * @throws PhpfastcacheLogicException |
|
| 134 | + */ |
|
| 135 | + public function setScopeName(string $scopeName): Config |
|
| 136 | + { |
|
| 137 | + return $this->setProperty('scopeName', $scopeName); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public function getCollectionName(): string |
|
| 144 | + { |
|
| 145 | + return $this->collectionName; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param string $collectionName |
|
| 150 | + * @return Config |
|
| 151 | + * @throws PhpfastcacheLogicException |
|
| 152 | + */ |
|
| 153 | + public function setCollectionName(string $collectionName): Config |
|
| 154 | + { |
|
| 155 | + return $this->setProperty('collectionName', $collectionName); |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -51,8 +51,7 @@ |
||
| 51 | 51 | /** |
| 52 | 52 | * @return int |
| 53 | 53 | */ |
| 54 | - public function getPort() |
|
| 55 | - { |
|
| 54 | + public function getPort() { |
|
| 56 | 55 | return $this->port; |
| 57 | 56 | } |
| 58 | 57 | |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Item implements ExtendedCacheItemInterface |
| 23 | 23 | { |
| 24 | - use TaggableCacheItemTrait; |
|
| 24 | + use TaggableCacheItemTrait; |
|
| 25 | 25 | |
| 26 | - protected function getDriverClass(): string |
|
| 27 | - { |
|
| 28 | - return Driver::class; |
|
| 29 | - } |
|
| 26 | + protected function getDriverClass(): string |
|
| 27 | + { |
|
| 28 | + return Driver::class; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -36,94 +36,94 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Driver implements AggregatablePoolInterface |
| 38 | 38 | { |
| 39 | - use IOHelperTrait; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return bool |
|
| 43 | - * @throws PhpfastcacheIOException |
|
| 44 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 45 | - */ |
|
| 46 | - public function driverCheck(): bool |
|
| 47 | - { |
|
| 48 | - return is_writable($this->getPath()) || mkdir($concurrentDirectory = $this->getPath(), $this->getDefaultChmod(), true) || is_dir($concurrentDirectory); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - protected function driverConnect(): bool |
|
| 55 | - { |
|
| 56 | - return true; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param ExtendedCacheItemInterface $item |
|
| 61 | - * @return ?array<string, mixed> |
|
| 62 | - * @throws PhpfastcacheIOException |
|
| 63 | - */ |
|
| 64 | - protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
| 65 | - { |
|
| 66 | - $filePath = $this->getFilePath($item->getKey(), true); |
|
| 67 | - |
|
| 68 | - try { |
|
| 69 | - $content = $this->readFile($filePath); |
|
| 70 | - } catch (PhpfastcacheIOException) { |
|
| 71 | - return null; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return $this->decode($content); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param ExtendedCacheItemInterface $item |
|
| 79 | - * @return bool |
|
| 80 | - * @throws PhpfastcacheIOException |
|
| 81 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 82 | - * @throws PhpfastcacheLogicException |
|
| 83 | - */ |
|
| 84 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 85 | - { |
|
| 86 | - |
|
| 87 | - $filePath = $this->getFilePath($item->getKey()); |
|
| 88 | - $data = $this->encode($this->driverPreWrap($item)); |
|
| 89 | - |
|
| 90 | - try { |
|
| 91 | - return $this->writeFile($filePath, $data, $this->getConfig()->isSecureFileManipulation()); |
|
| 92 | - } catch (Exception) { |
|
| 93 | - return false; |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param string $key |
|
| 99 | - * @param string $encodedKey |
|
| 100 | - * @return bool |
|
| 101 | - * @throws PhpfastcacheIOException |
|
| 102 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 103 | - */ |
|
| 104 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
| 105 | - { |
|
| 106 | - |
|
| 107 | - $filePath = $this->getFilePath($key, true); |
|
| 108 | - if (\file_exists($filePath) && @\unlink($filePath)) { |
|
| 109 | - \clearstatcache(true, $filePath); |
|
| 110 | - $dir = \dirname($filePath); |
|
| 111 | - if (!(new FilesystemIterator($dir))->valid()) { |
|
| 112 | - \rmdir($dir); |
|
| 113 | - } |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return bool |
|
| 122 | - * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException |
|
| 123 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 124 | - */ |
|
| 125 | - protected function driverClear(): bool |
|
| 126 | - { |
|
| 127 | - return Directory::rrmdir($this->getPath(true)); |
|
| 128 | - } |
|
| 39 | + use IOHelperTrait; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return bool |
|
| 43 | + * @throws PhpfastcacheIOException |
|
| 44 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 45 | + */ |
|
| 46 | + public function driverCheck(): bool |
|
| 47 | + { |
|
| 48 | + return is_writable($this->getPath()) || mkdir($concurrentDirectory = $this->getPath(), $this->getDefaultChmod(), true) || is_dir($concurrentDirectory); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + protected function driverConnect(): bool |
|
| 55 | + { |
|
| 56 | + return true; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param ExtendedCacheItemInterface $item |
|
| 61 | + * @return ?array<string, mixed> |
|
| 62 | + * @throws PhpfastcacheIOException |
|
| 63 | + */ |
|
| 64 | + protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
| 65 | + { |
|
| 66 | + $filePath = $this->getFilePath($item->getKey(), true); |
|
| 67 | + |
|
| 68 | + try { |
|
| 69 | + $content = $this->readFile($filePath); |
|
| 70 | + } catch (PhpfastcacheIOException) { |
|
| 71 | + return null; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return $this->decode($content); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param ExtendedCacheItemInterface $item |
|
| 79 | + * @return bool |
|
| 80 | + * @throws PhpfastcacheIOException |
|
| 81 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 82 | + * @throws PhpfastcacheLogicException |
|
| 83 | + */ |
|
| 84 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 85 | + { |
|
| 86 | + |
|
| 87 | + $filePath = $this->getFilePath($item->getKey()); |
|
| 88 | + $data = $this->encode($this->driverPreWrap($item)); |
|
| 89 | + |
|
| 90 | + try { |
|
| 91 | + return $this->writeFile($filePath, $data, $this->getConfig()->isSecureFileManipulation()); |
|
| 92 | + } catch (Exception) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param string $key |
|
| 99 | + * @param string $encodedKey |
|
| 100 | + * @return bool |
|
| 101 | + * @throws PhpfastcacheIOException |
|
| 102 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 103 | + */ |
|
| 104 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
| 105 | + { |
|
| 106 | + |
|
| 107 | + $filePath = $this->getFilePath($key, true); |
|
| 108 | + if (\file_exists($filePath) && @\unlink($filePath)) { |
|
| 109 | + \clearstatcache(true, $filePath); |
|
| 110 | + $dir = \dirname($filePath); |
|
| 111 | + if (!(new FilesystemIterator($dir))->valid()) { |
|
| 112 | + \rmdir($dir); |
|
| 113 | + } |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return bool |
|
| 122 | + * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException |
|
| 123 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 124 | + */ |
|
| 125 | + protected function driverClear(): bool |
|
| 126 | + { |
|
| 127 | + return Directory::rrmdir($this->getPath(true)); |
|
| 128 | + } |
|
| 129 | 129 | } |
@@ -67,7 +67,8 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | try { |
| 69 | 69 | $content = $this->readFile($filePath); |
| 70 | - } catch (PhpfastcacheIOException) { |
|
| 70 | + } |
|
| 71 | + catch (PhpfastcacheIOException) { |
|
| 71 | 72 | return null; |
| 72 | 73 | } |
| 73 | 74 | |
@@ -89,7 +90,8 @@ discard block |
||
| 89 | 90 | |
| 90 | 91 | try { |
| 91 | 92 | return $this->writeFile($filePath, $data, $this->getConfig()->isSecureFileManipulation()); |
| 92 | - } catch (Exception) { |
|
| 93 | + } |
|
| 94 | + catch (Exception) { |
|
| 93 | 95 | return false; |
| 94 | 96 | } |
| 95 | 97 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Item implements ExtendedCacheItemInterface |
| 23 | 23 | { |
| 24 | - use TaggableCacheItemTrait; |
|
| 24 | + use TaggableCacheItemTrait; |
|
| 25 | 25 | |
| 26 | - protected function getDriverClass(): string |
|
| 27 | - { |
|
| 28 | - return Driver::class; |
|
| 29 | - } |
|
| 26 | + protected function getDriverClass(): string |
|
| 27 | + { |
|
| 28 | + return Driver::class; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Item implements ExtendedCacheItemInterface |
| 23 | 23 | { |
| 24 | - use TaggableCacheItemTrait; |
|
| 24 | + use TaggableCacheItemTrait; |
|
| 25 | 25 | |
| 26 | - protected function getDriverClass(): string |
|
| 27 | - { |
|
| 28 | - return Driver::class; |
|
| 29 | - } |
|
| 26 | + protected function getDriverClass(): string |
|
| 27 | + { |
|
| 28 | + return Driver::class; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Item implements ExtendedCacheItemInterface |
| 23 | 23 | { |
| 24 | - use TaggableCacheItemTrait; |
|
| 24 | + use TaggableCacheItemTrait; |
|
| 25 | 25 | |
| 26 | - protected function getDriverClass(): string |
|
| 27 | - { |
|
| 28 | - return Driver::class; |
|
| 29 | - } |
|
| 26 | + protected function getDriverClass(): string |
|
| 27 | + { |
|
| 28 | + return Driver::class; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -42,189 +42,189 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class Driver implements AggregatablePoolInterface |
| 44 | 44 | { |
| 45 | - use TaggableCacheItemPoolTrait { |
|
| 46 | - __construct as protected __parentConstruct; |
|
| 47 | - } |
|
| 48 | - use MemcacheDriverCollisionDetectorTrait; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Driver constructor. |
|
| 52 | - * @param ConfigurationOption $config |
|
| 53 | - * @param string $instanceId |
|
| 54 | - * @param EventManagerInterface $em |
|
| 55 | - * @throws PhpfastcacheDriverConnectException |
|
| 56 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 57 | - * @throws PhpfastcacheCoreException |
|
| 58 | - * @throws PhpfastcacheDriverCheckException |
|
| 59 | - * @throws PhpfastcacheIOException |
|
| 60 | - */ |
|
| 61 | - public function __construct(ConfigurationOption $config, string $instanceId, EventManagerInterface $em) |
|
| 62 | - { |
|
| 63 | - self::checkCollision('Memcached'); |
|
| 64 | - $this->__parentConstruct($config, $instanceId, $em); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return bool |
|
| 69 | - */ |
|
| 70 | - public function driverCheck(): bool |
|
| 71 | - { |
|
| 72 | - return class_exists('Memcached'); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @return DriverStatistic |
|
| 77 | - */ |
|
| 78 | - public function getStats(): DriverStatistic |
|
| 79 | - { |
|
| 80 | - $stats = current($this->instance->getStats()); |
|
| 81 | - $stats['uptime'] = $stats['uptime'] ?? 0; |
|
| 82 | - $stats['bytes'] = $stats['bytes'] ?? 0; |
|
| 83 | - $stats['version'] = $stats['version'] ?? $this->instance->getVersion(); |
|
| 84 | - |
|
| 85 | - $date = (new DateTime())->setTimestamp(time() - $stats['uptime']); |
|
| 86 | - |
|
| 87 | - return (new DriverStatistic()) |
|
| 88 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 89 | - ->setInfo(sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats['version'], $date->format(DATE_RFC2822))) |
|
| 90 | - ->setRawData($stats) |
|
| 91 | - ->setSize((int)$stats['bytes']); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return bool |
|
| 96 | - * @throws PhpfastcacheDriverException |
|
| 97 | - */ |
|
| 98 | - protected function driverConnect(): bool |
|
| 99 | - { |
|
| 100 | - $this->instance = new MemcachedSoftware(); |
|
| 101 | - $optPrefix = $this->getConfig()->getOptPrefix(); |
|
| 102 | - $this->instance->setOption(MemcachedSoftware::OPT_BINARY_PROTOCOL, true); |
|
| 103 | - |
|
| 104 | - if ($optPrefix) { |
|
| 105 | - $this->instance->setOption(MemcachedSoftware::OPT_PREFIX_KEY, $optPrefix); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - foreach ($this->getConfig()->getServers() as $server) { |
|
| 109 | - $connected = false; |
|
| 110 | - /** |
|
| 111 | - * If path is provided we consider it as an UNIX Socket |
|
| 112 | - */ |
|
| 113 | - if (!empty($server['path'])) { |
|
| 114 | - $connected = $this->instance->addServer($server['path'], 0); |
|
| 115 | - } elseif (!empty($server['host'])) { |
|
| 116 | - $connected = $this->instance->addServer($server['host'], $server['port']); |
|
| 117 | - } |
|
| 118 | - if (!empty($server['saslUser']) && !empty($server['saslPassword'])) { |
|
| 119 | - $this->instance->setSaslAuthData($server['saslUser'], $server['saslPassword']); |
|
| 120 | - } |
|
| 121 | - if (!$connected) { |
|
| 122 | - throw new PhpfastcacheDriverConnectException( |
|
| 123 | - sprintf( |
|
| 124 | - 'Failed to connect to memcache host/path "%s".', |
|
| 125 | - $server['host'] ?: $server['path'], |
|
| 126 | - ) |
|
| 127 | - ); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Since Memcached does not throw |
|
| 133 | - * any error if not connected ... |
|
| 134 | - */ |
|
| 135 | - $version = $this->instance->getVersion(); |
|
| 136 | - if (!$version || $this->instance->getResultCode() !== MemcachedSoftware::RES_SUCCESS) { |
|
| 137 | - throw new PhpfastcacheDriverException('Memcached seems to not be connected'); |
|
| 138 | - } |
|
| 139 | - return true; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param ExtendedCacheItemInterface $item |
|
| 144 | - * @return ?array<string, mixed> |
|
| 145 | - */ |
|
| 146 | - protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
| 147 | - { |
|
| 148 | - $val = $this->instance->get($item->getKey()); |
|
| 149 | - |
|
| 150 | - if (empty($val) || !\is_array($val)) { |
|
| 151 | - return null; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $val; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param ExtendedCacheItemInterface ...$items |
|
| 159 | - * @return array<array<string, mixed>> |
|
| 160 | - */ |
|
| 161 | - protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array |
|
| 162 | - { |
|
| 163 | - $keys = $this->getKeys($items); |
|
| 164 | - |
|
| 165 | - $val = $this->instance->getMulti($keys); |
|
| 166 | - |
|
| 167 | - if (empty($val) || !\is_array($val)) { |
|
| 168 | - return []; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $val; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @return array<string, mixed> |
|
| 177 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 178 | - */ |
|
| 179 | - protected function driverReadAllKeys(string $pattern = ''): iterable |
|
| 180 | - { |
|
| 181 | - if ($pattern !== '') { |
|
| 182 | - $this->throwUnsupportedDriverReadAllPattern('https://www.php.net/manual/en/memcached.getallkeys.php'); |
|
| 183 | - } |
|
| 184 | - $keys = $this->instance->getAllKeys(); |
|
| 185 | - |
|
| 186 | - if (is_iterable($keys)) { |
|
| 187 | - return $keys; |
|
| 188 | - } else { |
|
| 189 | - return []; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param ExtendedCacheItemInterface $item |
|
| 195 | - * @return bool |
|
| 196 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 197 | - * @throws PhpfastcacheLogicException |
|
| 198 | - */ |
|
| 199 | - protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 200 | - { |
|
| 201 | - |
|
| 202 | - $ttl = $item->getExpirationDate()->getTimestamp() - time(); |
|
| 203 | - |
|
| 204 | - // Memcache will only allow a expiration timer less than 2592000 seconds, |
|
| 205 | - // otherwise, it will assume you're giving it a UNIX timestamp. |
|
| 206 | - if ($ttl > 2592000) { |
|
| 207 | - $ttl = time() + $ttl; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $ttl); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @param string $key |
|
| 215 | - * @param string $encodedKey |
|
| 216 | - * @return bool |
|
| 217 | - */ |
|
| 218 | - protected function driverDelete(string $key, string $encodedKey): bool |
|
| 219 | - { |
|
| 220 | - return $this->instance->delete($key); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @return bool |
|
| 225 | - */ |
|
| 226 | - protected function driverClear(): bool |
|
| 227 | - { |
|
| 228 | - return $this->instance->flush(); |
|
| 229 | - } |
|
| 45 | + use TaggableCacheItemPoolTrait { |
|
| 46 | + __construct as protected __parentConstruct; |
|
| 47 | + } |
|
| 48 | + use MemcacheDriverCollisionDetectorTrait; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Driver constructor. |
|
| 52 | + * @param ConfigurationOption $config |
|
| 53 | + * @param string $instanceId |
|
| 54 | + * @param EventManagerInterface $em |
|
| 55 | + * @throws PhpfastcacheDriverConnectException |
|
| 56 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 57 | + * @throws PhpfastcacheCoreException |
|
| 58 | + * @throws PhpfastcacheDriverCheckException |
|
| 59 | + * @throws PhpfastcacheIOException |
|
| 60 | + */ |
|
| 61 | + public function __construct(ConfigurationOption $config, string $instanceId, EventManagerInterface $em) |
|
| 62 | + { |
|
| 63 | + self::checkCollision('Memcached'); |
|
| 64 | + $this->__parentConstruct($config, $instanceId, $em); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return bool |
|
| 69 | + */ |
|
| 70 | + public function driverCheck(): bool |
|
| 71 | + { |
|
| 72 | + return class_exists('Memcached'); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @return DriverStatistic |
|
| 77 | + */ |
|
| 78 | + public function getStats(): DriverStatistic |
|
| 79 | + { |
|
| 80 | + $stats = current($this->instance->getStats()); |
|
| 81 | + $stats['uptime'] = $stats['uptime'] ?? 0; |
|
| 82 | + $stats['bytes'] = $stats['bytes'] ?? 0; |
|
| 83 | + $stats['version'] = $stats['version'] ?? $this->instance->getVersion(); |
|
| 84 | + |
|
| 85 | + $date = (new DateTime())->setTimestamp(time() - $stats['uptime']); |
|
| 86 | + |
|
| 87 | + return (new DriverStatistic()) |
|
| 88 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 89 | + ->setInfo(sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats['version'], $date->format(DATE_RFC2822))) |
|
| 90 | + ->setRawData($stats) |
|
| 91 | + ->setSize((int)$stats['bytes']); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return bool |
|
| 96 | + * @throws PhpfastcacheDriverException |
|
| 97 | + */ |
|
| 98 | + protected function driverConnect(): bool |
|
| 99 | + { |
|
| 100 | + $this->instance = new MemcachedSoftware(); |
|
| 101 | + $optPrefix = $this->getConfig()->getOptPrefix(); |
|
| 102 | + $this->instance->setOption(MemcachedSoftware::OPT_BINARY_PROTOCOL, true); |
|
| 103 | + |
|
| 104 | + if ($optPrefix) { |
|
| 105 | + $this->instance->setOption(MemcachedSoftware::OPT_PREFIX_KEY, $optPrefix); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + foreach ($this->getConfig()->getServers() as $server) { |
|
| 109 | + $connected = false; |
|
| 110 | + /** |
|
| 111 | + * If path is provided we consider it as an UNIX Socket |
|
| 112 | + */ |
|
| 113 | + if (!empty($server['path'])) { |
|
| 114 | + $connected = $this->instance->addServer($server['path'], 0); |
|
| 115 | + } elseif (!empty($server['host'])) { |
|
| 116 | + $connected = $this->instance->addServer($server['host'], $server['port']); |
|
| 117 | + } |
|
| 118 | + if (!empty($server['saslUser']) && !empty($server['saslPassword'])) { |
|
| 119 | + $this->instance->setSaslAuthData($server['saslUser'], $server['saslPassword']); |
|
| 120 | + } |
|
| 121 | + if (!$connected) { |
|
| 122 | + throw new PhpfastcacheDriverConnectException( |
|
| 123 | + sprintf( |
|
| 124 | + 'Failed to connect to memcache host/path "%s".', |
|
| 125 | + $server['host'] ?: $server['path'], |
|
| 126 | + ) |
|
| 127 | + ); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Since Memcached does not throw |
|
| 133 | + * any error if not connected ... |
|
| 134 | + */ |
|
| 135 | + $version = $this->instance->getVersion(); |
|
| 136 | + if (!$version || $this->instance->getResultCode() !== MemcachedSoftware::RES_SUCCESS) { |
|
| 137 | + throw new PhpfastcacheDriverException('Memcached seems to not be connected'); |
|
| 138 | + } |
|
| 139 | + return true; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param ExtendedCacheItemInterface $item |
|
| 144 | + * @return ?array<string, mixed> |
|
| 145 | + */ |
|
| 146 | + protected function driverRead(ExtendedCacheItemInterface $item): ?array |
|
| 147 | + { |
|
| 148 | + $val = $this->instance->get($item->getKey()); |
|
| 149 | + |
|
| 150 | + if (empty($val) || !\is_array($val)) { |
|
| 151 | + return null; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $val; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param ExtendedCacheItemInterface ...$items |
|
| 159 | + * @return array<array<string, mixed>> |
|
| 160 | + */ |
|
| 161 | + protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array |
|
| 162 | + { |
|
| 163 | + $keys = $this->getKeys($items); |
|
| 164 | + |
|
| 165 | + $val = $this->instance->getMulti($keys); |
|
| 166 | + |
|
| 167 | + if (empty($val) || !\is_array($val)) { |
|
| 168 | + return []; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $val; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @return array<string, mixed> |
|
| 177 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 178 | + */ |
|
| 179 | + protected function driverReadAllKeys(string $pattern = ''): iterable |
|
| 180 | + { |
|
| 181 | + if ($pattern !== '') { |
|
| 182 | + $this->throwUnsupportedDriverReadAllPattern('https://www.php.net/manual/en/memcached.getallkeys.php'); |
|
| 183 | + } |
|
| 184 | + $keys = $this->instance->getAllKeys(); |
|
| 185 | + |
|
| 186 | + if (is_iterable($keys)) { |
|
| 187 | + return $keys; |
|
| 188 | + } else { |
|
| 189 | + return []; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @param ExtendedCacheItemInterface $item |
|
| 195 | + * @return bool |
|
| 196 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 197 | + * @throws PhpfastcacheLogicException |
|
| 198 | + */ |
|
| 199 | + protected function driverWrite(ExtendedCacheItemInterface $item): bool |
|
| 200 | + { |
|
| 201 | + |
|
| 202 | + $ttl = $item->getExpirationDate()->getTimestamp() - time(); |
|
| 203 | + |
|
| 204 | + // Memcache will only allow a expiration timer less than 2592000 seconds, |
|
| 205 | + // otherwise, it will assume you're giving it a UNIX timestamp. |
|
| 206 | + if ($ttl > 2592000) { |
|
| 207 | + $ttl = time() + $ttl; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $this->instance->set($item->getKey(), $this->driverPreWrap($item), $ttl); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @param string $key |
|
| 215 | + * @param string $encodedKey |
|
| 216 | + * @return bool |
|
| 217 | + */ |
|
| 218 | + protected function driverDelete(string $key, string $encodedKey): bool |
|
| 219 | + { |
|
| 220 | + return $this->instance->delete($key); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @return bool |
|
| 225 | + */ |
|
| 226 | + protected function driverClear(): bool |
|
| 227 | + { |
|
| 228 | + return $this->instance->flush(); |
|
| 229 | + } |
|
| 230 | 230 | } |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | ->setData(implode(', ', array_keys($this->itemInstances))) |
| 79 | 79 | ->setInfo(sprintf("The memcache daemon v%s is up since %s.\n For more information see RawData.", $stats['version'], $date->format(DATE_RFC2822))) |
| 80 | 80 | ->setRawData($stats) |
| 81 | - ->setSize((int)$stats['bytes']); |
|
| 81 | + ->setSize((int) $stats['bytes']); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -58,8 +58,7 @@ discard block |
||
| 58 | 58 | * @throws PhpfastcacheDriverCheckException |
| 59 | 59 | * @throws PhpfastcacheIOException |
| 60 | 60 | */ |
| 61 | - public function __construct(ConfigurationOption $config, string $instanceId, EventManagerInterface $em) |
|
| 62 | - { |
|
| 61 | + public function __construct(ConfigurationOption $config, string $instanceId, EventManagerInterface $em) { |
|
| 63 | 62 | self::checkCollision('Memcached'); |
| 64 | 63 | $this->__parentConstruct($config, $instanceId, $em); |
| 65 | 64 | } |
@@ -112,7 +111,8 @@ discard block |
||
| 112 | 111 | */ |
| 113 | 112 | if (!empty($server['path'])) { |
| 114 | 113 | $connected = $this->instance->addServer($server['path'], 0); |
| 115 | - } elseif (!empty($server['host'])) { |
|
| 114 | + } |
|
| 115 | + elseif (!empty($server['host'])) { |
|
| 116 | 116 | $connected = $this->instance->addServer($server['host'], $server['port']); |
| 117 | 117 | } |
| 118 | 118 | if (!empty($server['saslUser']) && !empty($server['saslPassword'])) { |
@@ -185,7 +185,8 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | if (is_iterable($keys)) { |
| 187 | 187 | return $keys; |
| 188 | - } else { |
|
| 188 | + } |
|
| 189 | + else { |
|
| 189 | 190 | return []; |
| 190 | 191 | } |
| 191 | 192 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Item implements ExtendedCacheItemInterface |
| 23 | 23 | { |
| 24 | - use TaggableCacheItemTrait; |
|
| 24 | + use TaggableCacheItemTrait; |
|
| 25 | 25 | |
| 26 | - protected function getDriverClass(): string |
|
| 27 | - { |
|
| 28 | - return Driver::class; |
|
| 29 | - } |
|
| 26 | + protected function getDriverClass(): string |
|
| 27 | + { |
|
| 28 | + return Driver::class; |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -21,10 +21,10 @@ |
||
| 21 | 21 | |
| 22 | 22 | class Item implements ExtendedCacheItemInterface |
| 23 | 23 | { |
| 24 | - use TaggableCacheItemTrait; |
|
| 24 | + use TaggableCacheItemTrait; |
|
| 25 | 25 | |
| 26 | - protected function getDriverClass(): string |
|
| 27 | - { |
|
| 28 | - return Driver::class; |
|
| 29 | - } |
|
| 26 | + protected function getDriverClass(): string |
|
| 27 | + { |
|
| 28 | + return Driver::class; |
|
| 29 | + } |
|
| 30 | 30 | } |