@@ -37,25 +37,25 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface |
| 39 | 39 | { |
| 40 | - protected const CASSANDRA_KEY_SPACE = 'phpfastcache'; |
|
| 41 | - protected const CASSANDRA_TABLE = 'cacheItems'; |
|
| 42 | - |
|
| 43 | - use DriverBaseTrait; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public function driverCheck(): bool |
|
| 49 | - { |
|
| 50 | - return extension_loaded('Cassandra') && class_exists(Cassandra::class); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public function getHelp(): string |
|
| 57 | - { |
|
| 58 | - return <<<HELP |
|
| 40 | + protected const CASSANDRA_KEY_SPACE = 'phpfastcache'; |
|
| 41 | + protected const CASSANDRA_TABLE = 'cacheItems'; |
|
| 42 | + |
|
| 43 | + use DriverBaseTrait; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public function driverCheck(): bool |
|
| 49 | + { |
|
| 50 | + return extension_loaded('Cassandra') && class_exists(Cassandra::class); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public function getHelp(): string |
|
| 57 | + { |
|
| 58 | + return <<<HELP |
|
| 59 | 59 | <p> |
| 60 | 60 | To install the php Cassandra extension via Pecl: |
| 61 | 61 | <code>sudo pecl install cassandra</code> |
@@ -63,86 +63,86 @@ discard block |
||
| 63 | 63 | Please note that this repository only provide php stubs and C/C++ sources, it does NOT provide php client. |
| 64 | 64 | </p> |
| 65 | 65 | HELP; |
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return DriverStatistic |
|
| 70 | - * @throws Exception |
|
| 71 | - */ |
|
| 72 | - public function getStats(): DriverStatistic |
|
| 73 | - { |
|
| 74 | - $result = $this->instance->execute( |
|
| 75 | - new Cassandra\SimpleStatement( |
|
| 76 | - sprintf( |
|
| 77 | - 'SELECT SUM(cache_length) as cache_size FROM %s.%s', |
|
| 78 | - self::CASSANDRA_KEY_SPACE, |
|
| 79 | - self::CASSANDRA_TABLE |
|
| 80 | - ) |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - return (new DriverStatistic()) |
|
| 85 | - ->setSize($result->first()['cache_size']) |
|
| 86 | - ->setRawData([]) |
|
| 87 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 88 | - ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return bool |
|
| 93 | - * @throws PhpfastcacheLogicException |
|
| 94 | - * @throws Exception |
|
| 95 | - */ |
|
| 96 | - protected function driverConnect(): bool |
|
| 97 | - { |
|
| 98 | - if ($this->instance instanceof CassandraSession) { |
|
| 99 | - throw new PhpfastcacheLogicException('Already connected to Couchbase server'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $clientConfig = $this->getConfig(); |
|
| 103 | - |
|
| 104 | - $clusterBuilder = Cassandra::cluster() |
|
| 105 | - ->withContactPoints($clientConfig->getHost()) |
|
| 106 | - ->withPort($clientConfig->getPort()); |
|
| 107 | - |
|
| 108 | - if (!empty($clientConfig->isSslEnabled())) { |
|
| 109 | - if (!empty($clientConfig->isSslVerify())) { |
|
| 110 | - $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); |
|
| 111 | - } else { |
|
| 112 | - $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_NONE); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $clusterBuilder->withSSL($sslBuilder->build()); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $clusterBuilder->withConnectTimeout($clientConfig->getTimeout()); |
|
| 119 | - |
|
| 120 | - if ($clientConfig->getUsername()) { |
|
| 121 | - $clusterBuilder->withCredentials($clientConfig->getUsername(), $clientConfig->getPassword()); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - $this->instance = $clusterBuilder->build()->connect(); |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * In case of emergency: |
|
| 128 | - * $this->instance->execute( |
|
| 129 | - * new Cassandra\SimpleStatement(\sprintf("DROP KEYSPACE %s;", self::CASSANDRA_KEY_SPACE)) |
|
| 130 | - * ); |
|
| 131 | - */ |
|
| 132 | - |
|
| 133 | - $this->instance->execute( |
|
| 134 | - new Cassandra\SimpleStatement( |
|
| 135 | - sprintf( |
|
| 136 | - "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", |
|
| 137 | - self::CASSANDRA_KEY_SPACE |
|
| 138 | - ) |
|
| 139 | - ) |
|
| 140 | - ); |
|
| 141 | - $this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE))); |
|
| 142 | - $this->instance->execute( |
|
| 143 | - new Cassandra\SimpleStatement( |
|
| 144 | - sprintf( |
|
| 145 | - ' |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return DriverStatistic |
|
| 70 | + * @throws Exception |
|
| 71 | + */ |
|
| 72 | + public function getStats(): DriverStatistic |
|
| 73 | + { |
|
| 74 | + $result = $this->instance->execute( |
|
| 75 | + new Cassandra\SimpleStatement( |
|
| 76 | + sprintf( |
|
| 77 | + 'SELECT SUM(cache_length) as cache_size FROM %s.%s', |
|
| 78 | + self::CASSANDRA_KEY_SPACE, |
|
| 79 | + self::CASSANDRA_TABLE |
|
| 80 | + ) |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + return (new DriverStatistic()) |
|
| 85 | + ->setSize($result->first()['cache_size']) |
|
| 86 | + ->setRawData([]) |
|
| 87 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 88 | + ->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.'); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return bool |
|
| 93 | + * @throws PhpfastcacheLogicException |
|
| 94 | + * @throws Exception |
|
| 95 | + */ |
|
| 96 | + protected function driverConnect(): bool |
|
| 97 | + { |
|
| 98 | + if ($this->instance instanceof CassandraSession) { |
|
| 99 | + throw new PhpfastcacheLogicException('Already connected to Couchbase server'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $clientConfig = $this->getConfig(); |
|
| 103 | + |
|
| 104 | + $clusterBuilder = Cassandra::cluster() |
|
| 105 | + ->withContactPoints($clientConfig->getHost()) |
|
| 106 | + ->withPort($clientConfig->getPort()); |
|
| 107 | + |
|
| 108 | + if (!empty($clientConfig->isSslEnabled())) { |
|
| 109 | + if (!empty($clientConfig->isSslVerify())) { |
|
| 110 | + $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); |
|
| 111 | + } else { |
|
| 112 | + $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_NONE); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $clusterBuilder->withSSL($sslBuilder->build()); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $clusterBuilder->withConnectTimeout($clientConfig->getTimeout()); |
|
| 119 | + |
|
| 120 | + if ($clientConfig->getUsername()) { |
|
| 121 | + $clusterBuilder->withCredentials($clientConfig->getUsername(), $clientConfig->getPassword()); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + $this->instance = $clusterBuilder->build()->connect(); |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * In case of emergency: |
|
| 128 | + * $this->instance->execute( |
|
| 129 | + * new Cassandra\SimpleStatement(\sprintf("DROP KEYSPACE %s;", self::CASSANDRA_KEY_SPACE)) |
|
| 130 | + * ); |
|
| 131 | + */ |
|
| 132 | + |
|
| 133 | + $this->instance->execute( |
|
| 134 | + new Cassandra\SimpleStatement( |
|
| 135 | + sprintf( |
|
| 136 | + "CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", |
|
| 137 | + self::CASSANDRA_KEY_SPACE |
|
| 138 | + ) |
|
| 139 | + ) |
|
| 140 | + ); |
|
| 141 | + $this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE))); |
|
| 142 | + $this->instance->execute( |
|
| 143 | + new Cassandra\SimpleStatement( |
|
| 144 | + sprintf( |
|
| 145 | + ' |
|
| 146 | 146 | CREATE TABLE IF NOT EXISTS %s ( |
| 147 | 147 | cache_uuid uuid, |
| 148 | 148 | cache_id varchar, |
@@ -152,74 +152,74 @@ discard block |
||
| 152 | 152 | cache_length int, |
| 153 | 153 | PRIMARY KEY (cache_id) |
| 154 | 154 | );', |
| 155 | - self::CASSANDRA_TABLE |
|
| 156 | - ) |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - |
|
| 160 | - return true; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @param CacheItemInterface $item |
|
| 165 | - * @return null|array |
|
| 166 | - */ |
|
| 167 | - protected function driverRead(CacheItemInterface $item) |
|
| 168 | - { |
|
| 169 | - try { |
|
| 170 | - $options = new Cassandra\ExecutionOptions( |
|
| 171 | - [ |
|
| 172 | - 'arguments' => ['cache_id' => $item->getKey()], |
|
| 173 | - 'page_size' => 1, |
|
| 174 | - ] |
|
| 175 | - ); |
|
| 176 | - $query = sprintf( |
|
| 177 | - 'SELECT cache_data FROM %s.%s WHERE cache_id = :cache_id;', |
|
| 178 | - self::CASSANDRA_KEY_SPACE, |
|
| 179 | - self::CASSANDRA_TABLE |
|
| 180 | - ); |
|
| 181 | - $results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
| 182 | - |
|
| 183 | - if ($results instanceof Cassandra\Rows && $results->count() === 1) { |
|
| 184 | - return $this->decode($results->first()['cache_data']); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return null; |
|
| 188 | - } catch (Exception $e) { |
|
| 189 | - return null; |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param CacheItemInterface $item |
|
| 195 | - * @return bool |
|
| 196 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 197 | - */ |
|
| 198 | - protected function driverWrite(CacheItemInterface $item): bool |
|
| 199 | - { |
|
| 200 | - /** |
|
| 201 | - * Check for Cross-Driver type confusion |
|
| 202 | - */ |
|
| 203 | - if ($item instanceof Item) { |
|
| 204 | - try { |
|
| 205 | - $cacheData = $this->encode($this->driverPreWrap($item)); |
|
| 206 | - $options = new Cassandra\ExecutionOptions( |
|
| 207 | - [ |
|
| 208 | - 'arguments' => [ |
|
| 209 | - 'cache_uuid' => new Cassandra\Uuid(), |
|
| 210 | - 'cache_id' => $item->getKey(), |
|
| 211 | - 'cache_data' => $cacheData, |
|
| 212 | - 'cache_creation_date' => new Cassandra\Timestamp((new DateTime())->getTimestamp()), |
|
| 213 | - 'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp()), |
|
| 214 | - 'cache_length' => strlen($cacheData), |
|
| 215 | - ], |
|
| 216 | - 'consistency' => Cassandra::CONSISTENCY_ALL, |
|
| 217 | - 'serial_consistency' => Cassandra::CONSISTENCY_SERIAL, |
|
| 218 | - ] |
|
| 219 | - ); |
|
| 220 | - |
|
| 221 | - $query = sprintf( |
|
| 222 | - 'INSERT INTO %s.%s |
|
| 155 | + self::CASSANDRA_TABLE |
|
| 156 | + ) |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + |
|
| 160 | + return true; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * @param CacheItemInterface $item |
|
| 165 | + * @return null|array |
|
| 166 | + */ |
|
| 167 | + protected function driverRead(CacheItemInterface $item) |
|
| 168 | + { |
|
| 169 | + try { |
|
| 170 | + $options = new Cassandra\ExecutionOptions( |
|
| 171 | + [ |
|
| 172 | + 'arguments' => ['cache_id' => $item->getKey()], |
|
| 173 | + 'page_size' => 1, |
|
| 174 | + ] |
|
| 175 | + ); |
|
| 176 | + $query = sprintf( |
|
| 177 | + 'SELECT cache_data FROM %s.%s WHERE cache_id = :cache_id;', |
|
| 178 | + self::CASSANDRA_KEY_SPACE, |
|
| 179 | + self::CASSANDRA_TABLE |
|
| 180 | + ); |
|
| 181 | + $results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
| 182 | + |
|
| 183 | + if ($results instanceof Cassandra\Rows && $results->count() === 1) { |
|
| 184 | + return $this->decode($results->first()['cache_data']); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return null; |
|
| 188 | + } catch (Exception $e) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @param CacheItemInterface $item |
|
| 195 | + * @return bool |
|
| 196 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 197 | + */ |
|
| 198 | + protected function driverWrite(CacheItemInterface $item): bool |
|
| 199 | + { |
|
| 200 | + /** |
|
| 201 | + * Check for Cross-Driver type confusion |
|
| 202 | + */ |
|
| 203 | + if ($item instanceof Item) { |
|
| 204 | + try { |
|
| 205 | + $cacheData = $this->encode($this->driverPreWrap($item)); |
|
| 206 | + $options = new Cassandra\ExecutionOptions( |
|
| 207 | + [ |
|
| 208 | + 'arguments' => [ |
|
| 209 | + 'cache_uuid' => new Cassandra\Uuid(), |
|
| 210 | + 'cache_id' => $item->getKey(), |
|
| 211 | + 'cache_data' => $cacheData, |
|
| 212 | + 'cache_creation_date' => new Cassandra\Timestamp((new DateTime())->getTimestamp()), |
|
| 213 | + 'cache_expiration_date' => new Cassandra\Timestamp($item->getExpirationDate()->getTimestamp()), |
|
| 214 | + 'cache_length' => strlen($cacheData), |
|
| 215 | + ], |
|
| 216 | + 'consistency' => Cassandra::CONSISTENCY_ALL, |
|
| 217 | + 'serial_consistency' => Cassandra::CONSISTENCY_SERIAL, |
|
| 218 | + ] |
|
| 219 | + ); |
|
| 220 | + |
|
| 221 | + $query = sprintf( |
|
| 222 | + 'INSERT INTO %s.%s |
|
| 223 | 223 | ( |
| 224 | 224 | cache_uuid, |
| 225 | 225 | cache_id, |
@@ -230,94 +230,94 @@ discard block |
||
| 230 | 230 | ) |
| 231 | 231 | VALUES (:cache_uuid, :cache_id, :cache_data, :cache_creation_date, :cache_expiration_date, :cache_length); |
| 232 | 232 | ', |
| 233 | - self::CASSANDRA_KEY_SPACE, |
|
| 234 | - self::CASSANDRA_TABLE |
|
| 235 | - ); |
|
| 236 | - |
|
| 237 | - $result = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
| 238 | - /** |
|
| 239 | - * There's no real way atm |
|
| 240 | - * to know if the item has |
|
| 241 | - * been really upserted |
|
| 242 | - */ |
|
| 243 | - return $result instanceof Cassandra\Rows; |
|
| 244 | - } catch (InvalidArgumentException $e) { |
|
| 245 | - throw new PhpfastcacheInvalidArgumentException($e, 0, $e); |
|
| 246 | - } |
|
| 247 | - } else { |
|
| 248 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /******************** |
|
| 233 | + self::CASSANDRA_KEY_SPACE, |
|
| 234 | + self::CASSANDRA_TABLE |
|
| 235 | + ); |
|
| 236 | + |
|
| 237 | + $result = $this->instance->execute(new Cassandra\SimpleStatement($query), $options); |
|
| 238 | + /** |
|
| 239 | + * There's no real way atm |
|
| 240 | + * to know if the item has |
|
| 241 | + * been really upserted |
|
| 242 | + */ |
|
| 243 | + return $result instanceof Cassandra\Rows; |
|
| 244 | + } catch (InvalidArgumentException $e) { |
|
| 245 | + throw new PhpfastcacheInvalidArgumentException($e, 0, $e); |
|
| 246 | + } |
|
| 247 | + } else { |
|
| 248 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /******************** |
|
| 253 | 253 | * |
| 254 | 254 | * PSR-6 Extended Methods |
| 255 | 255 | * |
| 256 | 256 | *******************/ |
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * @param CacheItemInterface $item |
|
| 260 | - * @return bool |
|
| 261 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 262 | - */ |
|
| 263 | - protected function driverDelete(CacheItemInterface $item): bool |
|
| 264 | - { |
|
| 265 | - /** |
|
| 266 | - * Check for Cross-Driver type confusion |
|
| 267 | - */ |
|
| 268 | - if ($item instanceof Item) { |
|
| 269 | - try { |
|
| 270 | - $options = new Cassandra\ExecutionOptions( |
|
| 271 | - [ |
|
| 272 | - 'arguments' => [ |
|
| 273 | - 'cache_id' => $item->getKey(), |
|
| 274 | - ], |
|
| 275 | - ] |
|
| 276 | - ); |
|
| 277 | - $result = $this->instance->execute( |
|
| 278 | - new Cassandra\SimpleStatement( |
|
| 279 | - sprintf( |
|
| 280 | - 'DELETE FROM %s.%s WHERE cache_id = :cache_id;', |
|
| 281 | - self::CASSANDRA_KEY_SPACE, |
|
| 282 | - self::CASSANDRA_TABLE |
|
| 283 | - ) |
|
| 284 | - ), |
|
| 285 | - $options |
|
| 286 | - ); |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * There's no real way atm |
|
| 290 | - * to know if the item has |
|
| 291 | - * been really deleted |
|
| 292 | - */ |
|
| 293 | - return $result instanceof Cassandra\Rows; |
|
| 294 | - } catch (Exception $e) { |
|
| 295 | - return false; |
|
| 296 | - } |
|
| 297 | - } else { |
|
| 298 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * @return bool |
|
| 304 | - */ |
|
| 305 | - protected function driverClear(): bool |
|
| 306 | - { |
|
| 307 | - try { |
|
| 308 | - $this->instance->execute( |
|
| 309 | - new Cassandra\SimpleStatement( |
|
| 310 | - sprintf( |
|
| 311 | - 'TRUNCATE %s.%s;', |
|
| 312 | - self::CASSANDRA_KEY_SPACE, |
|
| 313 | - self::CASSANDRA_TABLE |
|
| 314 | - ) |
|
| 315 | - ) |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - return true; |
|
| 319 | - } catch (Exception $e) { |
|
| 320 | - return false; |
|
| 321 | - } |
|
| 322 | - } |
|
| 258 | + /** |
|
| 259 | + * @param CacheItemInterface $item |
|
| 260 | + * @return bool |
|
| 261 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 262 | + */ |
|
| 263 | + protected function driverDelete(CacheItemInterface $item): bool |
|
| 264 | + { |
|
| 265 | + /** |
|
| 266 | + * Check for Cross-Driver type confusion |
|
| 267 | + */ |
|
| 268 | + if ($item instanceof Item) { |
|
| 269 | + try { |
|
| 270 | + $options = new Cassandra\ExecutionOptions( |
|
| 271 | + [ |
|
| 272 | + 'arguments' => [ |
|
| 273 | + 'cache_id' => $item->getKey(), |
|
| 274 | + ], |
|
| 275 | + ] |
|
| 276 | + ); |
|
| 277 | + $result = $this->instance->execute( |
|
| 278 | + new Cassandra\SimpleStatement( |
|
| 279 | + sprintf( |
|
| 280 | + 'DELETE FROM %s.%s WHERE cache_id = :cache_id;', |
|
| 281 | + self::CASSANDRA_KEY_SPACE, |
|
| 282 | + self::CASSANDRA_TABLE |
|
| 283 | + ) |
|
| 284 | + ), |
|
| 285 | + $options |
|
| 286 | + ); |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * There's no real way atm |
|
| 290 | + * to know if the item has |
|
| 291 | + * been really deleted |
|
| 292 | + */ |
|
| 293 | + return $result instanceof Cassandra\Rows; |
|
| 294 | + } catch (Exception $e) { |
|
| 295 | + return false; |
|
| 296 | + } |
|
| 297 | + } else { |
|
| 298 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * @return bool |
|
| 304 | + */ |
|
| 305 | + protected function driverClear(): bool |
|
| 306 | + { |
|
| 307 | + try { |
|
| 308 | + $this->instance->execute( |
|
| 309 | + new Cassandra\SimpleStatement( |
|
| 310 | + sprintf( |
|
| 311 | + 'TRUNCATE %s.%s;', |
|
| 312 | + self::CASSANDRA_KEY_SPACE, |
|
| 313 | + self::CASSANDRA_TABLE |
|
| 314 | + ) |
|
| 315 | + ) |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + return true; |
|
| 319 | + } catch (Exception $e) { |
|
| 320 | + return false; |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | 323 | } |
@@ -20,23 +20,23 @@ |
||
| 20 | 20 | |
| 21 | 21 | class Config extends ConfigurationOption |
| 22 | 22 | { |
| 23 | - protected $awareOfUntrustableData = false; |
|
| 23 | + protected $awareOfUntrustableData = false; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return bool |
|
| 27 | - */ |
|
| 28 | - public function isAwareOfUntrustableData(): bool |
|
| 29 | - { |
|
| 30 | - return $this->awareOfUntrustableData; |
|
| 31 | - } |
|
| 25 | + /** |
|
| 26 | + * @return bool |
|
| 27 | + */ |
|
| 28 | + public function isAwareOfUntrustableData(): bool |
|
| 29 | + { |
|
| 30 | + return $this->awareOfUntrustableData; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param bool $awareOfUntrustableData |
|
| 35 | - * @return Config |
|
| 36 | - */ |
|
| 37 | - public function setAwareOfUntrustableData(bool $awareOfUntrustableData): Config |
|
| 38 | - { |
|
| 39 | - $this->awareOfUntrustableData = $awareOfUntrustableData; |
|
| 40 | - return $this; |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * @param bool $awareOfUntrustableData |
|
| 35 | + * @return Config |
|
| 36 | + */ |
|
| 37 | + public function setAwareOfUntrustableData(bool $awareOfUntrustableData): Config |
|
| 38 | + { |
|
| 39 | + $this->awareOfUntrustableData = $awareOfUntrustableData; |
|
| 40 | + return $this; |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | \ No newline at end of file |
@@ -27,35 +27,35 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class Item implements ExtendedCacheItemInterface |
| 29 | 29 | { |
| 30 | - use ItemBaseTrait { |
|
| 31 | - ItemBaseTrait::__construct as __BaseConstruct; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Item constructor. |
|
| 36 | - * @param Driver $driver |
|
| 37 | - * @param $key |
|
| 38 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | - */ |
|
| 40 | - public function __construct(CookieDriver $driver, $key) |
|
| 41 | - { |
|
| 42 | - $this->__BaseConstruct($driver, $key); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param ExtendedCacheItemPoolInterface $driver |
|
| 48 | - * @return static |
|
| 49 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 50 | - */ |
|
| 51 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 52 | - { |
|
| 53 | - if ($driver instanceof CookieDriver) { |
|
| 54 | - $this->driver = $driver; |
|
| 55 | - |
|
| 56 | - return $this; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 60 | - } |
|
| 30 | + use ItemBaseTrait { |
|
| 31 | + ItemBaseTrait::__construct as __BaseConstruct; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Item constructor. |
|
| 36 | + * @param Driver $driver |
|
| 37 | + * @param $key |
|
| 38 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | + */ |
|
| 40 | + public function __construct(CookieDriver $driver, $key) |
|
| 41 | + { |
|
| 42 | + $this->__BaseConstruct($driver, $key); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param ExtendedCacheItemPoolInterface $driver |
|
| 48 | + * @return static |
|
| 49 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 50 | + */ |
|
| 51 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 52 | + { |
|
| 53 | + if ($driver instanceof CookieDriver) { |
|
| 54 | + $this->driver = $driver; |
|
| 55 | + |
|
| 56 | + return $this; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | \ No newline at end of file |
@@ -30,157 +30,157 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class Driver implements ExtendedCacheItemPoolInterface |
| 32 | 32 | { |
| 33 | - use DriverBaseTrait; |
|
| 34 | - |
|
| 35 | - protected const PREFIX = 'PFC_'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @return bool |
|
| 39 | - */ |
|
| 40 | - public function driverCheck(): bool |
|
| 41 | - { |
|
| 42 | - if (!$this->getConfig()->isAwareOfUntrustableData()) { |
|
| 43 | - throw new PhpfastcacheDriverException( |
|
| 44 | - 'You have to setup the config "awareOfUntrustableData" to "TRUE" to confirm that you are aware that this driver does not use reliable storage as it may be corrupted by end-user.' |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - return function_exists('setcookie'); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return DriverStatistic |
|
| 52 | - */ |
|
| 53 | - public function getStats(): DriverStatistic |
|
| 54 | - { |
|
| 55 | - $size = 0; |
|
| 56 | - $stat = new DriverStatistic(); |
|
| 57 | - $stat->setData($_COOKIE); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Only count PFC Cookie |
|
| 61 | - */ |
|
| 62 | - foreach ($_COOKIE as $key => $value) { |
|
| 63 | - if (strpos($key, self::PREFIX) === 0) { |
|
| 64 | - $size += strlen($value); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $stat->setSize($size); |
|
| 69 | - |
|
| 70 | - return $stat; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param CacheItemInterface $item |
|
| 75 | - * @return null|array |
|
| 76 | - * @throws PhpfastcacheDriverException |
|
| 77 | - */ |
|
| 78 | - protected function driverRead(CacheItemInterface $item) |
|
| 79 | - { |
|
| 80 | - $this->driverConnect(); |
|
| 81 | - $keyword = self::PREFIX . $item->getKey(); |
|
| 82 | - $x = isset($_COOKIE[$keyword]) ? json_decode($_COOKIE[$keyword], true) : false; |
|
| 83 | - |
|
| 84 | - if ($x == false) { |
|
| 85 | - return null; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - if (!is_scalar($this->driverUnwrapData($x)) && !is_null($this->driverUnwrapData($x))) { |
|
| 89 | - throw new PhpfastcacheDriverException('Hacking attempt: The decoding returned a non-scalar value, Cookie driver does not allow this.'); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $x; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return bool |
|
| 97 | - */ |
|
| 98 | - protected function driverConnect(): bool |
|
| 99 | - { |
|
| 100 | - return !(!array_key_exists('_pfc', $_COOKIE) && !@setcookie('_pfc', '1', 10)); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param CacheItemInterface $item |
|
| 105 | - * @return bool |
|
| 106 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 107 | - */ |
|
| 108 | - protected function driverWrite(CacheItemInterface $item): bool |
|
| 109 | - { |
|
| 110 | - /** |
|
| 111 | - * Check for Cross-Driver type confusion |
|
| 112 | - */ |
|
| 113 | - if ($item instanceof Item) { |
|
| 114 | - $this->driverConnect(); |
|
| 115 | - $keyword = self::PREFIX . $item->getKey(); |
|
| 116 | - $v = json_encode($this->driverPreWrap($item)); |
|
| 117 | - |
|
| 118 | - if ($this->getConfig()->getLimitedMemoryByObject() !== null && strlen($v) > $this->getConfig()->getLimitedMemoryByObject()) { |
|
| 119 | - return false; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - return setcookie($keyword, $v, $item->getExpirationDate()->getTimestamp(), '/'); |
|
| 123 | - } |
|
| 124 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param string $key |
|
| 129 | - * @return int |
|
| 130 | - */ |
|
| 131 | - protected function driverReadExpirationDate($key): int |
|
| 132 | - { |
|
| 133 | - $this->driverConnect(); |
|
| 134 | - $keyword = self::PREFIX . $key; |
|
| 135 | - $x = isset($_COOKIE[$keyword]) ? $this->decode(json_decode($_COOKIE[$keyword])->t) : 0; |
|
| 136 | - |
|
| 137 | - return $x ? $x - time() : $x; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param CacheItemInterface $item |
|
| 142 | - * @return bool |
|
| 143 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 144 | - */ |
|
| 145 | - protected function driverDelete(CacheItemInterface $item): bool |
|
| 146 | - { |
|
| 147 | - /** |
|
| 148 | - * Check for Cross-Driver type confusion |
|
| 149 | - */ |
|
| 150 | - if ($item instanceof Item) { |
|
| 151 | - $this->driverConnect(); |
|
| 152 | - $keyword = self::PREFIX . $item->getKey(); |
|
| 153 | - $_COOKIE[$keyword] = null; |
|
| 154 | - |
|
| 155 | - return @setcookie($keyword, null, -10); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /******************** |
|
| 33 | + use DriverBaseTrait; |
|
| 34 | + |
|
| 35 | + protected const PREFIX = 'PFC_'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @return bool |
|
| 39 | + */ |
|
| 40 | + public function driverCheck(): bool |
|
| 41 | + { |
|
| 42 | + if (!$this->getConfig()->isAwareOfUntrustableData()) { |
|
| 43 | + throw new PhpfastcacheDriverException( |
|
| 44 | + 'You have to setup the config "awareOfUntrustableData" to "TRUE" to confirm that you are aware that this driver does not use reliable storage as it may be corrupted by end-user.' |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + return function_exists('setcookie'); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return DriverStatistic |
|
| 52 | + */ |
|
| 53 | + public function getStats(): DriverStatistic |
|
| 54 | + { |
|
| 55 | + $size = 0; |
|
| 56 | + $stat = new DriverStatistic(); |
|
| 57 | + $stat->setData($_COOKIE); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Only count PFC Cookie |
|
| 61 | + */ |
|
| 62 | + foreach ($_COOKIE as $key => $value) { |
|
| 63 | + if (strpos($key, self::PREFIX) === 0) { |
|
| 64 | + $size += strlen($value); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $stat->setSize($size); |
|
| 69 | + |
|
| 70 | + return $stat; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param CacheItemInterface $item |
|
| 75 | + * @return null|array |
|
| 76 | + * @throws PhpfastcacheDriverException |
|
| 77 | + */ |
|
| 78 | + protected function driverRead(CacheItemInterface $item) |
|
| 79 | + { |
|
| 80 | + $this->driverConnect(); |
|
| 81 | + $keyword = self::PREFIX . $item->getKey(); |
|
| 82 | + $x = isset($_COOKIE[$keyword]) ? json_decode($_COOKIE[$keyword], true) : false; |
|
| 83 | + |
|
| 84 | + if ($x == false) { |
|
| 85 | + return null; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + if (!is_scalar($this->driverUnwrapData($x)) && !is_null($this->driverUnwrapData($x))) { |
|
| 89 | + throw new PhpfastcacheDriverException('Hacking attempt: The decoding returned a non-scalar value, Cookie driver does not allow this.'); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $x; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return bool |
|
| 97 | + */ |
|
| 98 | + protected function driverConnect(): bool |
|
| 99 | + { |
|
| 100 | + return !(!array_key_exists('_pfc', $_COOKIE) && !@setcookie('_pfc', '1', 10)); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param CacheItemInterface $item |
|
| 105 | + * @return bool |
|
| 106 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 107 | + */ |
|
| 108 | + protected function driverWrite(CacheItemInterface $item): bool |
|
| 109 | + { |
|
| 110 | + /** |
|
| 111 | + * Check for Cross-Driver type confusion |
|
| 112 | + */ |
|
| 113 | + if ($item instanceof Item) { |
|
| 114 | + $this->driverConnect(); |
|
| 115 | + $keyword = self::PREFIX . $item->getKey(); |
|
| 116 | + $v = json_encode($this->driverPreWrap($item)); |
|
| 117 | + |
|
| 118 | + if ($this->getConfig()->getLimitedMemoryByObject() !== null && strlen($v) > $this->getConfig()->getLimitedMemoryByObject()) { |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + return setcookie($keyword, $v, $item->getExpirationDate()->getTimestamp(), '/'); |
|
| 123 | + } |
|
| 124 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param string $key |
|
| 129 | + * @return int |
|
| 130 | + */ |
|
| 131 | + protected function driverReadExpirationDate($key): int |
|
| 132 | + { |
|
| 133 | + $this->driverConnect(); |
|
| 134 | + $keyword = self::PREFIX . $key; |
|
| 135 | + $x = isset($_COOKIE[$keyword]) ? $this->decode(json_decode($_COOKIE[$keyword])->t) : 0; |
|
| 136 | + |
|
| 137 | + return $x ? $x - time() : $x; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param CacheItemInterface $item |
|
| 142 | + * @return bool |
|
| 143 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 144 | + */ |
|
| 145 | + protected function driverDelete(CacheItemInterface $item): bool |
|
| 146 | + { |
|
| 147 | + /** |
|
| 148 | + * Check for Cross-Driver type confusion |
|
| 149 | + */ |
|
| 150 | + if ($item instanceof Item) { |
|
| 151 | + $this->driverConnect(); |
|
| 152 | + $keyword = self::PREFIX . $item->getKey(); |
|
| 153 | + $_COOKIE[$keyword] = null; |
|
| 154 | + |
|
| 155 | + return @setcookie($keyword, null, -10); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /******************** |
|
| 162 | 162 | * |
| 163 | 163 | * PSR-6 Extended Methods |
| 164 | 164 | * |
| 165 | 165 | *******************/ |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function driverClear(): bool |
|
| 171 | - { |
|
| 172 | - $return = null; |
|
| 173 | - $this->driverConnect(); |
|
| 174 | - foreach ($_COOKIE as $keyword => $value) { |
|
| 175 | - if (strpos($keyword, self::PREFIX) !== false) { |
|
| 176 | - $_COOKIE[$keyword] = null; |
|
| 177 | - $result = @setcookie($keyword, null, -10); |
|
| 178 | - if ($return !== false) { |
|
| 179 | - $return = $result; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $return; |
|
| 185 | - } |
|
| 167 | + /** |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function driverClear(): bool |
|
| 171 | + { |
|
| 172 | + $return = null; |
|
| 173 | + $this->driverConnect(); |
|
| 174 | + foreach ($_COOKIE as $keyword => $value) { |
|
| 175 | + if (strpos($keyword, self::PREFIX) !== false) { |
|
| 176 | + $_COOKIE[$keyword] = null; |
|
| 177 | + $result = @setcookie($keyword, null, -10); |
|
| 178 | + if ($return !== false) { |
|
| 179 | + $return = $result; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $return; |
|
| 185 | + } |
|
| 186 | 186 | } |
@@ -27,34 +27,34 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class Item implements ExtendedCacheItemInterface |
| 29 | 29 | { |
| 30 | - use ItemBaseTrait { |
|
| 31 | - ItemBaseTrait::__construct as __BaseConstruct; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Item constructor. |
|
| 36 | - * @param Driver $driver |
|
| 37 | - * @param $key |
|
| 38 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | - */ |
|
| 40 | - public function __construct(DevnullDriver $driver, $key) |
|
| 41 | - { |
|
| 42 | - $this->__BaseConstruct($driver, $key); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param ExtendedCacheItemPoolInterface $driver |
|
| 47 | - * @return static |
|
| 48 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 49 | - */ |
|
| 50 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 51 | - { |
|
| 52 | - if ($driver instanceof DevnullDriver) { |
|
| 53 | - $this->driver = $driver; |
|
| 54 | - |
|
| 55 | - return $this; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 59 | - } |
|
| 30 | + use ItemBaseTrait { |
|
| 31 | + ItemBaseTrait::__construct as __BaseConstruct; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Item constructor. |
|
| 36 | + * @param Driver $driver |
|
| 37 | + * @param $key |
|
| 38 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | + */ |
|
| 40 | + public function __construct(DevnullDriver $driver, $key) |
|
| 41 | + { |
|
| 42 | + $this->__BaseConstruct($driver, $key); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param ExtendedCacheItemPoolInterface $driver |
|
| 47 | + * @return static |
|
| 48 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 49 | + */ |
|
| 50 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 51 | + { |
|
| 52 | + if ($driver instanceof DevnullDriver) { |
|
| 53 | + $this->driver = $driver; |
|
| 54 | + |
|
| 55 | + return $this; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |
@@ -30,92 +30,92 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class Driver implements ExtendedCacheItemPoolInterface |
| 32 | 32 | { |
| 33 | - use DriverBaseTrait; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @return bool |
|
| 37 | - */ |
|
| 38 | - public function driverCheck(): bool |
|
| 39 | - { |
|
| 40 | - return true; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @return DriverStatistic |
|
| 45 | - */ |
|
| 46 | - public function getStats(): DriverStatistic |
|
| 47 | - { |
|
| 48 | - $stat = new DriverStatistic(); |
|
| 49 | - $stat->setInfo('[Devnull] A void info string') |
|
| 50 | - ->setSize(0) |
|
| 51 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 52 | - ->setRawData(null); |
|
| 53 | - |
|
| 54 | - return $stat; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param CacheItemInterface $item |
|
| 59 | - * @return mixed |
|
| 60 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 61 | - */ |
|
| 62 | - protected function driverWrite(CacheItemInterface $item): bool |
|
| 63 | - { |
|
| 64 | - /** |
|
| 65 | - * Check for Cross-Driver type confusion |
|
| 66 | - */ |
|
| 67 | - if ($item instanceof Item) { |
|
| 68 | - return true; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param CacheItemInterface $item |
|
| 76 | - * @return null |
|
| 77 | - */ |
|
| 78 | - protected function driverRead(CacheItemInterface $item) |
|
| 79 | - { |
|
| 80 | - return null; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @param CacheItemInterface $item |
|
| 85 | - * @return bool |
|
| 86 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 87 | - */ |
|
| 88 | - protected function driverDelete(CacheItemInterface $item): bool |
|
| 89 | - { |
|
| 90 | - /** |
|
| 91 | - * Check for Cross-Driver type confusion |
|
| 92 | - */ |
|
| 93 | - if ($item instanceof Item) { |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - protected function driverClear(): bool |
|
| 104 | - { |
|
| 105 | - return true; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /******************** |
|
| 33 | + use DriverBaseTrait; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @return bool |
|
| 37 | + */ |
|
| 38 | + public function driverCheck(): bool |
|
| 39 | + { |
|
| 40 | + return true; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @return DriverStatistic |
|
| 45 | + */ |
|
| 46 | + public function getStats(): DriverStatistic |
|
| 47 | + { |
|
| 48 | + $stat = new DriverStatistic(); |
|
| 49 | + $stat->setInfo('[Devnull] A void info string') |
|
| 50 | + ->setSize(0) |
|
| 51 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 52 | + ->setRawData(null); |
|
| 53 | + |
|
| 54 | + return $stat; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param CacheItemInterface $item |
|
| 59 | + * @return mixed |
|
| 60 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 61 | + */ |
|
| 62 | + protected function driverWrite(CacheItemInterface $item): bool |
|
| 63 | + { |
|
| 64 | + /** |
|
| 65 | + * Check for Cross-Driver type confusion |
|
| 66 | + */ |
|
| 67 | + if ($item instanceof Item) { |
|
| 68 | + return true; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param CacheItemInterface $item |
|
| 76 | + * @return null |
|
| 77 | + */ |
|
| 78 | + protected function driverRead(CacheItemInterface $item) |
|
| 79 | + { |
|
| 80 | + return null; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @param CacheItemInterface $item |
|
| 85 | + * @return bool |
|
| 86 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 87 | + */ |
|
| 88 | + protected function driverDelete(CacheItemInterface $item): bool |
|
| 89 | + { |
|
| 90 | + /** |
|
| 91 | + * Check for Cross-Driver type confusion |
|
| 92 | + */ |
|
| 93 | + if ($item instanceof Item) { |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + protected function driverClear(): bool |
|
| 104 | + { |
|
| 105 | + return true; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /******************** |
|
| 109 | 109 | * |
| 110 | 110 | * PSR-6 Extended Methods |
| 111 | 111 | * |
| 112 | 112 | *******************/ |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * @return bool |
|
| 116 | - */ |
|
| 117 | - protected function driverConnect(): bool |
|
| 118 | - { |
|
| 119 | - return true; |
|
| 120 | - } |
|
| 114 | + /** |
|
| 115 | + * @return bool |
|
| 116 | + */ |
|
| 117 | + protected function driverConnect(): bool |
|
| 118 | + { |
|
| 119 | + return true; |
|
| 120 | + } |
|
| 121 | 121 | } |
| 122 | 122 | \ No newline at end of file |
@@ -26,35 +26,35 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Item implements ExtendedCacheItemInterface |
| 28 | 28 | { |
| 29 | - use ItemBaseTrait { |
|
| 30 | - ItemBaseTrait::__construct as __BaseConstruct; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Item constructor. |
|
| 36 | - * @param Driver $driver |
|
| 37 | - * @param $key |
|
| 38 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | - */ |
|
| 40 | - public function __construct(ZendDiskDriver $driver, $key) |
|
| 41 | - { |
|
| 42 | - $this->__BaseConstruct($driver, $key); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param ExtendedCacheItemPoolInterface $driver |
|
| 47 | - * @return static |
|
| 48 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 49 | - */ |
|
| 50 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 51 | - { |
|
| 52 | - if ($driver instanceof ZendDiskDriver) { |
|
| 53 | - $this->driver = $driver; |
|
| 54 | - |
|
| 55 | - return $this; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 59 | - } |
|
| 29 | + use ItemBaseTrait { |
|
| 30 | + ItemBaseTrait::__construct as __BaseConstruct; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Item constructor. |
|
| 36 | + * @param Driver $driver |
|
| 37 | + * @param $key |
|
| 38 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | + */ |
|
| 40 | + public function __construct(ZendDiskDriver $driver, $key) |
|
| 41 | + { |
|
| 42 | + $this->__BaseConstruct($driver, $key); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param ExtendedCacheItemPoolInterface $driver |
|
| 47 | + * @return static |
|
| 48 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 49 | + */ |
|
| 50 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 51 | + { |
|
| 52 | + if ($driver instanceof ZendDiskDriver) { |
|
| 53 | + $this->driver = $driver; |
|
| 54 | + |
|
| 55 | + return $this; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |
@@ -31,111 +31,111 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface |
| 33 | 33 | { |
| 34 | - use DriverBaseTrait; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @return bool |
|
| 38 | - */ |
|
| 39 | - public function driverCheck(): bool |
|
| 40 | - { |
|
| 41 | - return extension_loaded('Zend Data Cache') && function_exists('zend_disk_cache_store'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getHelp(): string |
|
| 48 | - { |
|
| 49 | - return <<<HELP |
|
| 34 | + use DriverBaseTrait; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @return bool |
|
| 38 | + */ |
|
| 39 | + public function driverCheck(): bool |
|
| 40 | + { |
|
| 41 | + return extension_loaded('Zend Data Cache') && function_exists('zend_disk_cache_store'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getHelp(): string |
|
| 48 | + { |
|
| 49 | + return <<<HELP |
|
| 50 | 50 | <p> |
| 51 | 51 | This driver rely on Zend Server 8.5+, see: https://www.zend.com/en/products/zend_server |
| 52 | 52 | </p> |
| 53 | 53 | HELP; |
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @return DriverStatistic |
|
| 58 | - */ |
|
| 59 | - public function getStats(): DriverStatistic |
|
| 60 | - { |
|
| 61 | - $stat = new DriverStatistic(); |
|
| 62 | - $stat->setInfo('[ZendDisk] A void info string') |
|
| 63 | - ->setSize(0) |
|
| 64 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 65 | - ->setRawData(false); |
|
| 66 | - |
|
| 67 | - return $stat; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return bool |
|
| 72 | - */ |
|
| 73 | - protected function driverConnect(): bool |
|
| 74 | - { |
|
| 75 | - return true; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param CacheItemInterface $item |
|
| 80 | - * @return null|array |
|
| 81 | - */ |
|
| 82 | - protected function driverRead(CacheItemInterface $item) |
|
| 83 | - { |
|
| 84 | - $data = zend_disk_cache_fetch($item->getKey()); |
|
| 85 | - if ($data === false) { |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $data; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param CacheItemInterface $item |
|
| 94 | - * @return mixed |
|
| 95 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 96 | - */ |
|
| 97 | - protected function driverWrite(CacheItemInterface $item): bool |
|
| 98 | - { |
|
| 99 | - /** |
|
| 100 | - * Check for Cross-Driver type confusion |
|
| 101 | - */ |
|
| 102 | - if ($item instanceof Item) { |
|
| 103 | - $ttl = $item->getExpirationDate()->getTimestamp() - time(); |
|
| 104 | - |
|
| 105 | - return zend_disk_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /******************** |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @return DriverStatistic |
|
| 58 | + */ |
|
| 59 | + public function getStats(): DriverStatistic |
|
| 60 | + { |
|
| 61 | + $stat = new DriverStatistic(); |
|
| 62 | + $stat->setInfo('[ZendDisk] A void info string') |
|
| 63 | + ->setSize(0) |
|
| 64 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
| 65 | + ->setRawData(false); |
|
| 66 | + |
|
| 67 | + return $stat; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return bool |
|
| 72 | + */ |
|
| 73 | + protected function driverConnect(): bool |
|
| 74 | + { |
|
| 75 | + return true; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param CacheItemInterface $item |
|
| 80 | + * @return null|array |
|
| 81 | + */ |
|
| 82 | + protected function driverRead(CacheItemInterface $item) |
|
| 83 | + { |
|
| 84 | + $data = zend_disk_cache_fetch($item->getKey()); |
|
| 85 | + if ($data === false) { |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $data; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param CacheItemInterface $item |
|
| 94 | + * @return mixed |
|
| 95 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 96 | + */ |
|
| 97 | + protected function driverWrite(CacheItemInterface $item): bool |
|
| 98 | + { |
|
| 99 | + /** |
|
| 100 | + * Check for Cross-Driver type confusion |
|
| 101 | + */ |
|
| 102 | + if ($item instanceof Item) { |
|
| 103 | + $ttl = $item->getExpirationDate()->getTimestamp() - time(); |
|
| 104 | + |
|
| 105 | + return zend_disk_cache_store($item->getKey(), $this->driverPreWrap($item), ($ttl > 0 ? $ttl : 0)); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /******************** |
|
| 112 | 112 | * |
| 113 | 113 | * PSR-6 Extended Methods |
| 114 | 114 | * |
| 115 | 115 | *******************/ |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @param CacheItemInterface $item |
|
| 119 | - * @return bool |
|
| 120 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 121 | - */ |
|
| 122 | - protected function driverDelete(CacheItemInterface $item): bool |
|
| 123 | - { |
|
| 124 | - /** |
|
| 125 | - * Check for Cross-Driver type confusion |
|
| 126 | - */ |
|
| 127 | - if ($item instanceof Item) { |
|
| 128 | - return (bool)zend_disk_cache_delete($item->getKey()); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - protected function driverClear(): bool |
|
| 138 | - { |
|
| 139 | - return @zend_disk_cache_clear(); |
|
| 140 | - } |
|
| 117 | + /** |
|
| 118 | + * @param CacheItemInterface $item |
|
| 119 | + * @return bool |
|
| 120 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 121 | + */ |
|
| 122 | + protected function driverDelete(CacheItemInterface $item): bool |
|
| 123 | + { |
|
| 124 | + /** |
|
| 125 | + * Check for Cross-Driver type confusion |
|
| 126 | + */ |
|
| 127 | + if ($item instanceof Item) { |
|
| 128 | + return (bool)zend_disk_cache_delete($item->getKey()); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + protected function driverClear(): bool |
|
| 138 | + { |
|
| 139 | + return @zend_disk_cache_clear(); |
|
| 140 | + } |
|
| 141 | 141 | } |
@@ -27,34 +27,34 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class Item implements ExtendedCacheItemInterface |
| 29 | 29 | { |
| 30 | - use ItemBaseTrait { |
|
| 31 | - ItemBaseTrait::__construct as __BaseConstruct; |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Item constructor. |
|
| 36 | - * @param Driver $driver |
|
| 37 | - * @param $key |
|
| 38 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | - */ |
|
| 40 | - public function __construct(MemstaticDriver $driver, $key) |
|
| 41 | - { |
|
| 42 | - $this->__BaseConstruct($driver, $key); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param ExtendedCacheItemPoolInterface $driver |
|
| 47 | - * @return static |
|
| 48 | - * @throws PhpfastcacheInvalidArgumentException |
|
| 49 | - */ |
|
| 50 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 51 | - { |
|
| 52 | - if ($driver instanceof MemstaticDriver) { |
|
| 53 | - $this->driver = $driver; |
|
| 54 | - |
|
| 55 | - return $this; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 59 | - } |
|
| 30 | + use ItemBaseTrait { |
|
| 31 | + ItemBaseTrait::__construct as __BaseConstruct; |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Item constructor. |
|
| 36 | + * @param Driver $driver |
|
| 37 | + * @param $key |
|
| 38 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 39 | + */ |
|
| 40 | + public function __construct(MemstaticDriver $driver, $key) |
|
| 41 | + { |
|
| 42 | + $this->__BaseConstruct($driver, $key); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param ExtendedCacheItemPoolInterface $driver |
|
| 47 | + * @return static |
|
| 48 | + * @throws PhpfastcacheInvalidArgumentException |
|
| 49 | + */ |
|
| 50 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
| 51 | + { |
|
| 52 | + if ($driver instanceof MemstaticDriver) { |
|
| 53 | + $this->driver = $driver; |
|
| 54 | + |
|
| 55 | + return $this; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |