@@ -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(SsdbDriver $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 SsdbDriver) { |
|
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(SsdbDriver $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 SsdbDriver) { |
|
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 |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | * @param $key |
38 | 38 | * @throws PhpfastcacheInvalidArgumentException |
39 | 39 | */ |
40 | - public function __construct(SsdbDriver $driver, $key) |
|
41 | - { |
|
40 | + public function __construct(SsdbDriver $driver, $key) { |
|
42 | 41 | $this->__BaseConstruct($driver, $key); |
43 | 42 | } |
44 | 43 | |
@@ -47,8 +46,7 @@ discard block |
||
47 | 46 | * @return static |
48 | 47 | * @throws PhpfastcacheInvalidArgumentException |
49 | 48 | */ |
50 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
51 | - { |
|
49 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) { |
|
52 | 50 | if ($driver instanceof SsdbDriver) { |
53 | 51 | $this->driver = $driver; |
54 | 52 |
@@ -20,158 +20,158 @@ |
||
20 | 20 | |
21 | 21 | class Config extends ConfigurationOption |
22 | 22 | { |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $host = '127.0.0.1'; |
|
27 | - /** |
|
28 | - * @var int |
|
29 | - */ |
|
30 | - protected $port = 9042; |
|
31 | - /** |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - protected $timeout = 2; |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $username = ''; |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $password = ''; |
|
43 | - /** |
|
44 | - * @var bool |
|
45 | - */ |
|
46 | - protected $sslEnabled = false; |
|
47 | - /** |
|
48 | - * @var bool |
|
49 | - */ |
|
50 | - protected $sslVerify = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function getHost(): string |
|
56 | - { |
|
57 | - return $this->host; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param string $host |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - public function setHost(string $host): self |
|
65 | - { |
|
66 | - $this->host = $host; |
|
67 | - return $this; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return int |
|
72 | - */ |
|
73 | - public function getPort(): int |
|
74 | - { |
|
75 | - return $this->port; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param int $port |
|
80 | - * @return self |
|
81 | - */ |
|
82 | - public function setPort(int $port): self |
|
83 | - { |
|
84 | - $this->port = $port; |
|
85 | - return $this; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return int |
|
90 | - */ |
|
91 | - public function getTimeout(): int |
|
92 | - { |
|
93 | - return $this->timeout; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @param int $timeout |
|
98 | - * @return self |
|
99 | - */ |
|
100 | - public function setTimeout(int $timeout): self |
|
101 | - { |
|
102 | - $this->timeout = $timeout; |
|
103 | - return $this; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getUsername(): string |
|
110 | - { |
|
111 | - return $this->username; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param string $username |
|
116 | - * @return self |
|
117 | - */ |
|
118 | - public function setUsername(string $username): self |
|
119 | - { |
|
120 | - $this->username = $username; |
|
121 | - return $this; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function getPassword(): string |
|
128 | - { |
|
129 | - return $this->password; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $password |
|
134 | - * @return self |
|
135 | - */ |
|
136 | - public function setPassword(string $password): self |
|
137 | - { |
|
138 | - $this->password = $password; |
|
139 | - return $this; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @return bool |
|
144 | - */ |
|
145 | - public function isSslEnabled(): bool |
|
146 | - { |
|
147 | - return $this->sslEnabled; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param bool $sslEnabled |
|
152 | - * @return self |
|
153 | - */ |
|
154 | - public function setSslEnabled(bool $sslEnabled): self |
|
155 | - { |
|
156 | - $this->sslEnabled = $sslEnabled; |
|
157 | - return $this; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function isSslVerify(): bool |
|
164 | - { |
|
165 | - return $this->sslVerify; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @param bool $sslVerify |
|
170 | - * @return self |
|
171 | - */ |
|
172 | - public function setSslVerify(bool $sslVerify): self |
|
173 | - { |
|
174 | - $this->sslVerify = $sslVerify; |
|
175 | - return $this; |
|
176 | - } |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $host = '127.0.0.1'; |
|
27 | + /** |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + protected $port = 9042; |
|
31 | + /** |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + protected $timeout = 2; |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $username = ''; |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $password = ''; |
|
43 | + /** |
|
44 | + * @var bool |
|
45 | + */ |
|
46 | + protected $sslEnabled = false; |
|
47 | + /** |
|
48 | + * @var bool |
|
49 | + */ |
|
50 | + protected $sslVerify = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function getHost(): string |
|
56 | + { |
|
57 | + return $this->host; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param string $host |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + public function setHost(string $host): self |
|
65 | + { |
|
66 | + $this->host = $host; |
|
67 | + return $this; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return int |
|
72 | + */ |
|
73 | + public function getPort(): int |
|
74 | + { |
|
75 | + return $this->port; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param int $port |
|
80 | + * @return self |
|
81 | + */ |
|
82 | + public function setPort(int $port): self |
|
83 | + { |
|
84 | + $this->port = $port; |
|
85 | + return $this; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return int |
|
90 | + */ |
|
91 | + public function getTimeout(): int |
|
92 | + { |
|
93 | + return $this->timeout; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @param int $timeout |
|
98 | + * @return self |
|
99 | + */ |
|
100 | + public function setTimeout(int $timeout): self |
|
101 | + { |
|
102 | + $this->timeout = $timeout; |
|
103 | + return $this; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getUsername(): string |
|
110 | + { |
|
111 | + return $this->username; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param string $username |
|
116 | + * @return self |
|
117 | + */ |
|
118 | + public function setUsername(string $username): self |
|
119 | + { |
|
120 | + $this->username = $username; |
|
121 | + return $this; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function getPassword(): string |
|
128 | + { |
|
129 | + return $this->password; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $password |
|
134 | + * @return self |
|
135 | + */ |
|
136 | + public function setPassword(string $password): self |
|
137 | + { |
|
138 | + $this->password = $password; |
|
139 | + return $this; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | + public function isSslEnabled(): bool |
|
146 | + { |
|
147 | + return $this->sslEnabled; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param bool $sslEnabled |
|
152 | + * @return self |
|
153 | + */ |
|
154 | + public function setSslEnabled(bool $sslEnabled): self |
|
155 | + { |
|
156 | + $this->sslEnabled = $sslEnabled; |
|
157 | + return $this; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function isSslVerify(): bool |
|
164 | + { |
|
165 | + return $this->sslVerify; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @param bool $sslVerify |
|
170 | + * @return self |
|
171 | + */ |
|
172 | + public function setSslVerify(bool $sslVerify): self |
|
173 | + { |
|
174 | + $this->sslVerify = $sslVerify; |
|
175 | + return $this; |
|
176 | + } |
|
177 | 177 | } |
178 | 178 | \ No newline at end of file |
@@ -28,34 +28,34 @@ |
||
28 | 28 | */ |
29 | 29 | class Item implements ExtendedCacheItemInterface |
30 | 30 | { |
31 | - use ItemBaseTrait { |
|
32 | - ItemBaseTrait::__construct as __BaseConstruct; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Item constructor. |
|
37 | - * @param Driver $driver |
|
38 | - * @param $key |
|
39 | - * @throws PhpfastcacheInvalidArgumentException |
|
40 | - */ |
|
41 | - public function __construct(CassandraDriver $driver, $key) |
|
42 | - { |
|
43 | - $this->__BaseConstruct($driver, $key); |
|
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 CassandraDriver) { |
|
54 | - $this->driver = $driver; |
|
55 | - |
|
56 | - return $this; |
|
57 | - } |
|
58 | - |
|
59 | - throw new PhpfastcacheInvalidArgumentException('Invalid driver instance'); |
|
60 | - } |
|
31 | + use ItemBaseTrait { |
|
32 | + ItemBaseTrait::__construct as __BaseConstruct; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Item constructor. |
|
37 | + * @param Driver $driver |
|
38 | + * @param $key |
|
39 | + * @throws PhpfastcacheInvalidArgumentException |
|
40 | + */ |
|
41 | + public function __construct(CassandraDriver $driver, $key) |
|
42 | + { |
|
43 | + $this->__BaseConstruct($driver, $key); |
|
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 CassandraDriver) { |
|
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 |
@@ -38,8 +38,7 @@ discard block |
||
38 | 38 | * @param $key |
39 | 39 | * @throws PhpfastcacheInvalidArgumentException |
40 | 40 | */ |
41 | - public function __construct(CassandraDriver $driver, $key) |
|
42 | - { |
|
41 | + public function __construct(CassandraDriver $driver, $key) { |
|
43 | 42 | $this->__BaseConstruct($driver, $key); |
44 | 43 | } |
45 | 44 | |
@@ -48,8 +47,7 @@ discard block |
||
48 | 47 | * @return static |
49 | 48 | * @throws PhpfastcacheInvalidArgumentException |
50 | 49 | */ |
51 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
52 | - { |
|
50 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) { |
|
53 | 51 | if ($driver instanceof CassandraDriver) { |
54 | 52 | $this->driver = $driver; |
55 | 53 |
@@ -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 | } |
@@ -108,7 +108,8 @@ discard block |
||
108 | 108 | if (!empty($clientConfig->isSslEnabled())) { |
109 | 109 | if (!empty($clientConfig->isSslVerify())) { |
110 | 110 | $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_PEER_CERT); |
111 | - } else { |
|
111 | + } |
|
112 | + else { |
|
112 | 113 | $sslBuilder = Cassandra::ssl()->withVerifyFlags(Cassandra::VERIFY_NONE); |
113 | 114 | } |
114 | 115 | |
@@ -164,8 +165,7 @@ discard block |
||
164 | 165 | * @param CacheItemInterface $item |
165 | 166 | * @return null|array |
166 | 167 | */ |
167 | - protected function driverRead(CacheItemInterface $item) |
|
168 | - { |
|
168 | + protected function driverRead(CacheItemInterface $item) { |
|
169 | 169 | try { |
170 | 170 | $options = new Cassandra\ExecutionOptions( |
171 | 171 | [ |
@@ -185,7 +185,8 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | return null; |
188 | - } catch (Exception $e) { |
|
188 | + } |
|
189 | + catch (Exception $e) { |
|
189 | 190 | return null; |
190 | 191 | } |
191 | 192 | } |
@@ -241,10 +242,12 @@ discard block |
||
241 | 242 | * been really upserted |
242 | 243 | */ |
243 | 244 | return $result instanceof Cassandra\Rows; |
244 | - } catch (InvalidArgumentException $e) { |
|
245 | + } |
|
246 | + catch (InvalidArgumentException $e) { |
|
245 | 247 | throw new PhpfastcacheInvalidArgumentException($e, 0, $e); |
246 | 248 | } |
247 | - } else { |
|
249 | + } |
|
250 | + else { |
|
248 | 251 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
249 | 252 | } |
250 | 253 | } |
@@ -291,10 +294,12 @@ discard block |
||
291 | 294 | * been really deleted |
292 | 295 | */ |
293 | 296 | return $result instanceof Cassandra\Rows; |
294 | - } catch (Exception $e) { |
|
297 | + } |
|
298 | + catch (Exception $e) { |
|
295 | 299 | return false; |
296 | 300 | } |
297 | - } else { |
|
301 | + } |
|
302 | + else { |
|
298 | 303 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
299 | 304 | } |
300 | 305 | } |
@@ -316,7 +321,8 @@ discard block |
||
316 | 321 | ); |
317 | 322 | |
318 | 323 | return true; |
319 | - } catch (Exception $e) { |
|
324 | + } |
|
325 | + catch (Exception $e) { |
|
320 | 326 | return false; |
321 | 327 | } |
322 | 328 | } |
@@ -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 |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | * @param $key |
38 | 38 | * @throws PhpfastcacheInvalidArgumentException |
39 | 39 | */ |
40 | - public function __construct(CookieDriver $driver, $key) |
|
41 | - { |
|
40 | + public function __construct(CookieDriver $driver, $key) { |
|
42 | 41 | $this->__BaseConstruct($driver, $key); |
43 | 42 | } |
44 | 43 | |
@@ -48,8 +47,7 @@ discard block |
||
48 | 47 | * @return static |
49 | 48 | * @throws PhpfastcacheInvalidArgumentException |
50 | 49 | */ |
51 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
52 | - { |
|
50 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) { |
|
53 | 51 | if ($driver instanceof CookieDriver) { |
54 | 52 | $this->driver = $driver; |
55 | 53 |
@@ -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 | } |
@@ -75,8 +75,7 @@ |
||
75 | 75 | * @return null|array |
76 | 76 | * @throws PhpfastcacheDriverException |
77 | 77 | */ |
78 | - protected function driverRead(CacheItemInterface $item) |
|
79 | - { |
|
78 | + protected function driverRead(CacheItemInterface $item) { |
|
80 | 79 | $this->driverConnect(); |
81 | 80 | $keyword = self::PREFIX . $item->getKey(); |
82 | 81 | $x = isset($_COOKIE[$keyword]) ? json_decode($_COOKIE[$keyword], true) : false; |
@@ -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 |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | * @param $key |
38 | 38 | * @throws PhpfastcacheInvalidArgumentException |
39 | 39 | */ |
40 | - public function __construct(DevnullDriver $driver, $key) |
|
41 | - { |
|
40 | + public function __construct(DevnullDriver $driver, $key) { |
|
42 | 41 | $this->__BaseConstruct($driver, $key); |
43 | 42 | } |
44 | 43 | |
@@ -47,8 +46,7 @@ discard block |
||
47 | 46 | * @return static |
48 | 47 | * @throws PhpfastcacheInvalidArgumentException |
49 | 48 | */ |
50 | - public function setDriver(ExtendedCacheItemPoolInterface $driver) |
|
51 | - { |
|
49 | + public function setDriver(ExtendedCacheItemPoolInterface $driver) { |
|
52 | 50 | if ($driver instanceof DevnullDriver) { |
53 | 51 | $this->driver = $driver; |
54 | 52 |
@@ -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 |
@@ -75,8 +75,7 @@ |
||
75 | 75 | * @param CacheItemInterface $item |
76 | 76 | * @return null |
77 | 77 | */ |
78 | - protected function driverRead(CacheItemInterface $item) |
|
79 | - { |
|
78 | + protected function driverRead(CacheItemInterface $item) { |
|
80 | 79 | return null; |
81 | 80 | } |
82 | 81 |