@@ -20,5 +20,5 @@ |
||
20 | 20 | |
21 | 21 | class Config extends ConfigurationOption |
22 | 22 | { |
23 | - use IOConfigurationOptionTrait; |
|
23 | + use IOConfigurationOptionTrait; |
|
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -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(SqliteDriver $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 SqliteDriver) { |
|
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(SqliteDriver $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 SqliteDriver) { |
|
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(SqliteDriver $driver, $key) |
|
41 | - { |
|
40 | + public function __construct(SqliteDriver $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 SqliteDriver) { |
53 | 51 | $this->driver = $driver; |
54 | 52 |
@@ -32,335 +32,335 @@ |
||
32 | 32 | */ |
33 | 33 | class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface |
34 | 34 | { |
35 | - use DriverBaseTrait, IOHelperTrait; |
|
36 | - |
|
37 | - /** |
|
38 | - * |
|
39 | - */ |
|
40 | - protected const INDEXING_FILE = 'indexing'; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $maxSize = 10; // 10 mb |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int |
|
49 | - */ |
|
50 | - protected $currentDB = 1; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - protected $SqliteDir = ''; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var PDO |
|
59 | - */ |
|
60 | - protected $indexing; |
|
61 | - |
|
62 | - /** |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - public function driverCheck(): bool |
|
66 | - { |
|
67 | - return extension_loaded('pdo_sqlite') && (is_writable($this->getSqliteDir()) || @mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return string |
|
72 | - * @throws PhpfastcacheCoreException |
|
73 | - */ |
|
74 | - public function getSqliteDir(): string |
|
75 | - { |
|
76 | - return $this->SqliteDir ?: $this->getPath(); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return array |
|
81 | - */ |
|
82 | - public function __sleep(): array |
|
83 | - { |
|
84 | - return array_diff(array_keys(get_object_vars($this)), ['indexing', 'instance']); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return bool |
|
89 | - * @throws PhpfastcacheIOException |
|
90 | - */ |
|
91 | - protected function driverConnect(): bool |
|
92 | - { |
|
93 | - if (!file_exists($this->getSqliteDir()) && !@mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)) { |
|
94 | - throw new PhpfastcacheIOException(sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath())); |
|
95 | - } |
|
96 | - if (!file_exists($this->getPath())) { |
|
97 | - if (!mkdir($this->getPath(), $this->getDefaultChmod(), true) |
|
98 | - ) { |
|
99 | - $this->fallback = true; |
|
100 | - } |
|
101 | - } |
|
102 | - $this->SqliteDir = $this->getPath(); |
|
103 | - |
|
104 | - return true; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param CacheItemInterface $item |
|
109 | - * @return null|array |
|
110 | - */ |
|
111 | - protected function driverRead(CacheItemInterface $item) |
|
112 | - { |
|
113 | - try { |
|
114 | - $stm = $this->getDb($item->getEncodedKey()) |
|
115 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
116 | - $stm->execute( |
|
117 | - [ |
|
118 | - ':keyword' => $item->getEncodedKey(), |
|
119 | - ] |
|
120 | - ); |
|
121 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
122 | - } catch (PDOException $e) { |
|
123 | - try { |
|
124 | - $stm = $this->getDb($item->getEncodedKey(), true) |
|
125 | - ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
126 | - $stm->execute( |
|
127 | - [ |
|
128 | - ':keyword' => $item->getEncodedKey(), |
|
129 | - ] |
|
130 | - ); |
|
131 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
132 | - } catch (PDOException $e) { |
|
133 | - return null; |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - if (isset($row['object'])) { |
|
138 | - return $this->decode($row['object']); |
|
139 | - } |
|
140 | - |
|
141 | - return null; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @param string $keyword |
|
146 | - * @param bool $reset |
|
147 | - * @return PDO |
|
148 | - */ |
|
149 | - public function getDb(string $keyword, bool $reset = false): PDO |
|
150 | - { |
|
151 | - /** |
|
152 | - * Default is phpfastcache |
|
153 | - */ |
|
154 | - $instant = $this->indexing($keyword); |
|
155 | - |
|
156 | - /** |
|
157 | - * init instant |
|
158 | - */ |
|
159 | - if (!isset($this->instance[$instant])) { |
|
160 | - // check DB Files ready or not |
|
161 | - $tableCreated = false; |
|
162 | - if ($reset || !file_exists($this->SqliteDir . '/db' . $instant)) { |
|
163 | - $tableCreated = true; |
|
164 | - } |
|
165 | - $PDO = new PDO('sqlite:' . $this->SqliteDir . '/db' . $instant); |
|
166 | - $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
167 | - |
|
168 | - if ($tableCreated) { |
|
169 | - $this->initDB($PDO); |
|
170 | - } |
|
171 | - |
|
172 | - $this->instance[$instant] = $PDO; |
|
173 | - unset($PDO); |
|
174 | - } |
|
175 | - |
|
176 | - return $this->instance[$instant]; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * INIT Instant DB |
|
181 | - * Return Database of Keyword |
|
182 | - * @param $keyword |
|
183 | - * @return int |
|
184 | - */ |
|
185 | - public function indexing($keyword) |
|
186 | - { |
|
187 | - if ($this->indexing == null) { |
|
188 | - $tableCreated = false; |
|
189 | - if (!file_exists($this->SqliteDir . '/indexing')) { |
|
190 | - $tableCreated = true; |
|
191 | - } |
|
192 | - |
|
193 | - $PDO = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE); |
|
194 | - $PDO->setAttribute( |
|
195 | - PDO::ATTR_ERRMODE, |
|
196 | - PDO::ERRMODE_EXCEPTION |
|
197 | - ); |
|
198 | - |
|
199 | - if ($tableCreated) { |
|
200 | - $this->initIndexing($PDO); |
|
201 | - } |
|
202 | - $this->indexing = $PDO; |
|
203 | - unset($PDO); |
|
204 | - |
|
205 | - $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); |
|
206 | - $stm->execute(); |
|
207 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
208 | - if (!isset($row['db'])) { |
|
209 | - $db = 1; |
|
210 | - } elseif ($row['db'] <= 1) { |
|
211 | - $db = 1; |
|
212 | - } else { |
|
213 | - $db = $row['db']; |
|
214 | - } |
|
215 | - |
|
216 | - // check file size |
|
217 | - |
|
218 | - $size = file_exists($this->SqliteDir . '/db' . $db) ? filesize($this->SqliteDir . '/db' . $db) : 1; |
|
219 | - $size = round($size / 1024 / 1024, 1); |
|
220 | - |
|
221 | - |
|
222 | - if ($size > $this->maxSize) { |
|
223 | - $db++; |
|
224 | - } |
|
225 | - $this->currentDB = $db; |
|
226 | - } |
|
227 | - |
|
228 | - // look for keyword |
|
229 | - $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); |
|
230 | - $stm->execute( |
|
231 | - [ |
|
232 | - ':keyword' => $keyword, |
|
233 | - ] |
|
234 | - ); |
|
235 | - $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
236 | - if (isset($row['db']) && $row['db'] != '') { |
|
237 | - $db = $row['db']; |
|
238 | - } else { |
|
239 | - /* |
|
35 | + use DriverBaseTrait, IOHelperTrait; |
|
36 | + |
|
37 | + /** |
|
38 | + * |
|
39 | + */ |
|
40 | + protected const INDEXING_FILE = 'indexing'; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $maxSize = 10; // 10 mb |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int |
|
49 | + */ |
|
50 | + protected $currentDB = 1; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + protected $SqliteDir = ''; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var PDO |
|
59 | + */ |
|
60 | + protected $indexing; |
|
61 | + |
|
62 | + /** |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + public function driverCheck(): bool |
|
66 | + { |
|
67 | + return extension_loaded('pdo_sqlite') && (is_writable($this->getSqliteDir()) || @mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return string |
|
72 | + * @throws PhpfastcacheCoreException |
|
73 | + */ |
|
74 | + public function getSqliteDir(): string |
|
75 | + { |
|
76 | + return $this->SqliteDir ?: $this->getPath(); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return array |
|
81 | + */ |
|
82 | + public function __sleep(): array |
|
83 | + { |
|
84 | + return array_diff(array_keys(get_object_vars($this)), ['indexing', 'instance']); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return bool |
|
89 | + * @throws PhpfastcacheIOException |
|
90 | + */ |
|
91 | + protected function driverConnect(): bool |
|
92 | + { |
|
93 | + if (!file_exists($this->getSqliteDir()) && !@mkdir($this->getSqliteDir(), $this->getDefaultChmod(), true)) { |
|
94 | + throw new PhpfastcacheIOException(sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath())); |
|
95 | + } |
|
96 | + if (!file_exists($this->getPath())) { |
|
97 | + if (!mkdir($this->getPath(), $this->getDefaultChmod(), true) |
|
98 | + ) { |
|
99 | + $this->fallback = true; |
|
100 | + } |
|
101 | + } |
|
102 | + $this->SqliteDir = $this->getPath(); |
|
103 | + |
|
104 | + return true; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param CacheItemInterface $item |
|
109 | + * @return null|array |
|
110 | + */ |
|
111 | + protected function driverRead(CacheItemInterface $item) |
|
112 | + { |
|
113 | + try { |
|
114 | + $stm = $this->getDb($item->getEncodedKey()) |
|
115 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
116 | + $stm->execute( |
|
117 | + [ |
|
118 | + ':keyword' => $item->getEncodedKey(), |
|
119 | + ] |
|
120 | + ); |
|
121 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
122 | + } catch (PDOException $e) { |
|
123 | + try { |
|
124 | + $stm = $this->getDb($item->getEncodedKey(), true) |
|
125 | + ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
|
126 | + $stm->execute( |
|
127 | + [ |
|
128 | + ':keyword' => $item->getEncodedKey(), |
|
129 | + ] |
|
130 | + ); |
|
131 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
132 | + } catch (PDOException $e) { |
|
133 | + return null; |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + if (isset($row['object'])) { |
|
138 | + return $this->decode($row['object']); |
|
139 | + } |
|
140 | + |
|
141 | + return null; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @param string $keyword |
|
146 | + * @param bool $reset |
|
147 | + * @return PDO |
|
148 | + */ |
|
149 | + public function getDb(string $keyword, bool $reset = false): PDO |
|
150 | + { |
|
151 | + /** |
|
152 | + * Default is phpfastcache |
|
153 | + */ |
|
154 | + $instant = $this->indexing($keyword); |
|
155 | + |
|
156 | + /** |
|
157 | + * init instant |
|
158 | + */ |
|
159 | + if (!isset($this->instance[$instant])) { |
|
160 | + // check DB Files ready or not |
|
161 | + $tableCreated = false; |
|
162 | + if ($reset || !file_exists($this->SqliteDir . '/db' . $instant)) { |
|
163 | + $tableCreated = true; |
|
164 | + } |
|
165 | + $PDO = new PDO('sqlite:' . $this->SqliteDir . '/db' . $instant); |
|
166 | + $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
167 | + |
|
168 | + if ($tableCreated) { |
|
169 | + $this->initDB($PDO); |
|
170 | + } |
|
171 | + |
|
172 | + $this->instance[$instant] = $PDO; |
|
173 | + unset($PDO); |
|
174 | + } |
|
175 | + |
|
176 | + return $this->instance[$instant]; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * INIT Instant DB |
|
181 | + * Return Database of Keyword |
|
182 | + * @param $keyword |
|
183 | + * @return int |
|
184 | + */ |
|
185 | + public function indexing($keyword) |
|
186 | + { |
|
187 | + if ($this->indexing == null) { |
|
188 | + $tableCreated = false; |
|
189 | + if (!file_exists($this->SqliteDir . '/indexing')) { |
|
190 | + $tableCreated = true; |
|
191 | + } |
|
192 | + |
|
193 | + $PDO = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE); |
|
194 | + $PDO->setAttribute( |
|
195 | + PDO::ATTR_ERRMODE, |
|
196 | + PDO::ERRMODE_EXCEPTION |
|
197 | + ); |
|
198 | + |
|
199 | + if ($tableCreated) { |
|
200 | + $this->initIndexing($PDO); |
|
201 | + } |
|
202 | + $this->indexing = $PDO; |
|
203 | + unset($PDO); |
|
204 | + |
|
205 | + $stm = $this->indexing->prepare("SELECT MAX(`db`) as `db` FROM `balancing`"); |
|
206 | + $stm->execute(); |
|
207 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
208 | + if (!isset($row['db'])) { |
|
209 | + $db = 1; |
|
210 | + } elseif ($row['db'] <= 1) { |
|
211 | + $db = 1; |
|
212 | + } else { |
|
213 | + $db = $row['db']; |
|
214 | + } |
|
215 | + |
|
216 | + // check file size |
|
217 | + |
|
218 | + $size = file_exists($this->SqliteDir . '/db' . $db) ? filesize($this->SqliteDir . '/db' . $db) : 1; |
|
219 | + $size = round($size / 1024 / 1024, 1); |
|
220 | + |
|
221 | + |
|
222 | + if ($size > $this->maxSize) { |
|
223 | + $db++; |
|
224 | + } |
|
225 | + $this->currentDB = $db; |
|
226 | + } |
|
227 | + |
|
228 | + // look for keyword |
|
229 | + $stm = $this->indexing->prepare("SELECT * FROM `balancing` WHERE `keyword`=:keyword LIMIT 1"); |
|
230 | + $stm->execute( |
|
231 | + [ |
|
232 | + ':keyword' => $keyword, |
|
233 | + ] |
|
234 | + ); |
|
235 | + $row = $stm->fetch(PDO::FETCH_ASSOC); |
|
236 | + if (isset($row['db']) && $row['db'] != '') { |
|
237 | + $db = $row['db']; |
|
238 | + } else { |
|
239 | + /* |
|
240 | 240 | * Insert new to Indexing |
241 | 241 | */ |
242 | - $db = $this->currentDB; |
|
243 | - $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); |
|
244 | - $stm->execute( |
|
245 | - [ |
|
246 | - ':keyword' => $keyword, |
|
247 | - ':db' => $db, |
|
248 | - ] |
|
249 | - ); |
|
250 | - } |
|
251 | - |
|
252 | - return $db; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * INIT Indexing DB |
|
257 | - * @param PDO $db |
|
258 | - */ |
|
259 | - public function initIndexing(PDO $db) |
|
260 | - { |
|
261 | - // delete everything before reset indexing |
|
262 | - $dir = opendir($this->SqliteDir); |
|
263 | - while ($file = readdir($dir)) { |
|
264 | - if ($file != '.' && $file != '..' && $file != 'indexing' && $file != 'dbfastcache') { |
|
265 | - unlink($this->SqliteDir . '/' . $file); |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - $db->exec('DROP TABLE if exists "balancing"'); |
|
270 | - $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)'); |
|
271 | - $db->exec('CREATE INDEX "db" ON "balancing" ("db")'); |
|
272 | - $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")'); |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * INIT NEW DB |
|
277 | - * @param PDO $db |
|
278 | - */ |
|
279 | - public function initDB(PDO $db) |
|
280 | - { |
|
281 | - $db->exec('drop table if exists "caching"'); |
|
282 | - $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)'); |
|
283 | - $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")'); |
|
284 | - $db->exec('CREATE INDEX "exp" ON "caching" ("exp")'); |
|
285 | - $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * @param CacheItemInterface $item |
|
290 | - * @return mixed |
|
291 | - * @throws PhpfastcacheInvalidArgumentException |
|
292 | - */ |
|
293 | - protected function driverWrite(CacheItemInterface $item): bool |
|
294 | - { |
|
295 | - /** |
|
296 | - * Check for Cross-Driver type confusion |
|
297 | - */ |
|
298 | - if ($item instanceof Item) { |
|
299 | - try { |
|
300 | - $stm = $this->getDb($item->getEncodedKey()) |
|
301 | - ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
302 | - $stm->execute( |
|
303 | - [ |
|
304 | - ':keyword' => $item->getEncodedKey(), |
|
305 | - ':object' => $this->encode($this->driverPreWrap($item)), |
|
306 | - ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
307 | - ] |
|
308 | - ); |
|
309 | - |
|
310 | - return true; |
|
311 | - } catch (PDOException $e) { |
|
312 | - return false; |
|
313 | - } |
|
314 | - } |
|
315 | - |
|
316 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @param CacheItemInterface $item |
|
321 | - * @return bool |
|
322 | - * @throws PhpfastcacheInvalidArgumentException |
|
323 | - */ |
|
324 | - protected function driverDelete(CacheItemInterface $item): bool |
|
325 | - { |
|
326 | - /** |
|
327 | - * Check for Cross-Driver type confusion |
|
328 | - */ |
|
329 | - if ($item instanceof Item) { |
|
330 | - try { |
|
331 | - $stm = $this->getDb($item->getEncodedKey()) |
|
332 | - ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); |
|
333 | - |
|
334 | - return $stm->execute( |
|
335 | - [ |
|
336 | - ':keyword' => $item->getEncodedKey(), |
|
337 | - ':U' => time(), |
|
338 | - ] |
|
339 | - ); |
|
340 | - } catch (PDOException $e) { |
|
341 | - return false; |
|
342 | - } |
|
343 | - } else { |
|
344 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * @return bool |
|
350 | - */ |
|
351 | - protected function driverClear(): bool |
|
352 | - { |
|
353 | - $this->instance = []; |
|
354 | - $this->indexing = null; |
|
355 | - |
|
356 | - // delete everything before reset indexing |
|
357 | - $dir = opendir($this->getSqliteDir()); |
|
358 | - while ($file = readdir($dir)) { |
|
359 | - if ($file != '.' && $file != '..') { |
|
360 | - unlink($this->getSqliteDir() . '/' . $file); |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - return true; |
|
365 | - } |
|
242 | + $db = $this->currentDB; |
|
243 | + $stm = $this->indexing->prepare("INSERT INTO `balancing` (`keyword`,`db`) VALUES(:keyword, :db)"); |
|
244 | + $stm->execute( |
|
245 | + [ |
|
246 | + ':keyword' => $keyword, |
|
247 | + ':db' => $db, |
|
248 | + ] |
|
249 | + ); |
|
250 | + } |
|
251 | + |
|
252 | + return $db; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * INIT Indexing DB |
|
257 | + * @param PDO $db |
|
258 | + */ |
|
259 | + public function initIndexing(PDO $db) |
|
260 | + { |
|
261 | + // delete everything before reset indexing |
|
262 | + $dir = opendir($this->SqliteDir); |
|
263 | + while ($file = readdir($dir)) { |
|
264 | + if ($file != '.' && $file != '..' && $file != 'indexing' && $file != 'dbfastcache') { |
|
265 | + unlink($this->SqliteDir . '/' . $file); |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + $db->exec('DROP TABLE if exists "balancing"'); |
|
270 | + $db->exec('CREATE TABLE "balancing" ("keyword" VARCHAR PRIMARY KEY NOT NULL UNIQUE, "db" INTEGER)'); |
|
271 | + $db->exec('CREATE INDEX "db" ON "balancing" ("db")'); |
|
272 | + $db->exec('CREATE UNIQUE INDEX "lookup" ON "balancing" ("keyword")'); |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * INIT NEW DB |
|
277 | + * @param PDO $db |
|
278 | + */ |
|
279 | + public function initDB(PDO $db) |
|
280 | + { |
|
281 | + $db->exec('drop table if exists "caching"'); |
|
282 | + $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)'); |
|
283 | + $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")'); |
|
284 | + $db->exec('CREATE INDEX "exp" ON "caching" ("exp")'); |
|
285 | + $db->exec('CREATE UNIQUE INDEX "keyword" ON "caching" ("keyword")'); |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * @param CacheItemInterface $item |
|
290 | + * @return mixed |
|
291 | + * @throws PhpfastcacheInvalidArgumentException |
|
292 | + */ |
|
293 | + protected function driverWrite(CacheItemInterface $item): bool |
|
294 | + { |
|
295 | + /** |
|
296 | + * Check for Cross-Driver type confusion |
|
297 | + */ |
|
298 | + if ($item instanceof Item) { |
|
299 | + try { |
|
300 | + $stm = $this->getDb($item->getEncodedKey()) |
|
301 | + ->prepare("INSERT OR REPLACE INTO `caching` (`keyword`,`object`,`exp`) values(:keyword,:object,:exp)"); |
|
302 | + $stm->execute( |
|
303 | + [ |
|
304 | + ':keyword' => $item->getEncodedKey(), |
|
305 | + ':object' => $this->encode($this->driverPreWrap($item)), |
|
306 | + ':exp' => $item->getExpirationDate()->getTimestamp(), |
|
307 | + ] |
|
308 | + ); |
|
309 | + |
|
310 | + return true; |
|
311 | + } catch (PDOException $e) { |
|
312 | + return false; |
|
313 | + } |
|
314 | + } |
|
315 | + |
|
316 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @param CacheItemInterface $item |
|
321 | + * @return bool |
|
322 | + * @throws PhpfastcacheInvalidArgumentException |
|
323 | + */ |
|
324 | + protected function driverDelete(CacheItemInterface $item): bool |
|
325 | + { |
|
326 | + /** |
|
327 | + * Check for Cross-Driver type confusion |
|
328 | + */ |
|
329 | + if ($item instanceof Item) { |
|
330 | + try { |
|
331 | + $stm = $this->getDb($item->getEncodedKey()) |
|
332 | + ->prepare("DELETE FROM `caching` WHERE (`exp` <= :U) OR (`keyword`=:keyword) "); |
|
333 | + |
|
334 | + return $stm->execute( |
|
335 | + [ |
|
336 | + ':keyword' => $item->getEncodedKey(), |
|
337 | + ':U' => time(), |
|
338 | + ] |
|
339 | + ); |
|
340 | + } catch (PDOException $e) { |
|
341 | + return false; |
|
342 | + } |
|
343 | + } else { |
|
344 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * @return bool |
|
350 | + */ |
|
351 | + protected function driverClear(): bool |
|
352 | + { |
|
353 | + $this->instance = []; |
|
354 | + $this->indexing = null; |
|
355 | + |
|
356 | + // delete everything before reset indexing |
|
357 | + $dir = opendir($this->getSqliteDir()); |
|
358 | + while ($file = readdir($dir)) { |
|
359 | + if ($file != '.' && $file != '..') { |
|
360 | + unlink($this->getSqliteDir() . '/' . $file); |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + return true; |
|
365 | + } |
|
366 | 366 | } |
@@ -108,8 +108,7 @@ discard block |
||
108 | 108 | * @param CacheItemInterface $item |
109 | 109 | * @return null|array |
110 | 110 | */ |
111 | - protected function driverRead(CacheItemInterface $item) |
|
112 | - { |
|
111 | + protected function driverRead(CacheItemInterface $item) { |
|
113 | 112 | try { |
114 | 113 | $stm = $this->getDb($item->getEncodedKey()) |
115 | 114 | ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
@@ -119,7 +118,8 @@ discard block |
||
119 | 118 | ] |
120 | 119 | ); |
121 | 120 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
122 | - } catch (PDOException $e) { |
|
121 | + } |
|
122 | + catch (PDOException $e) { |
|
123 | 123 | try { |
124 | 124 | $stm = $this->getDb($item->getEncodedKey(), true) |
125 | 125 | ->prepare("SELECT * FROM `caching` WHERE `keyword`=:keyword LIMIT 1"); |
@@ -129,7 +129,8 @@ discard block |
||
129 | 129 | ] |
130 | 130 | ); |
131 | 131 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
132 | - } catch (PDOException $e) { |
|
132 | + } |
|
133 | + catch (PDOException $e) { |
|
133 | 134 | return null; |
134 | 135 | } |
135 | 136 | } |
@@ -182,8 +183,7 @@ discard block |
||
182 | 183 | * @param $keyword |
183 | 184 | * @return int |
184 | 185 | */ |
185 | - public function indexing($keyword) |
|
186 | - { |
|
186 | + public function indexing($keyword) { |
|
187 | 187 | if ($this->indexing == null) { |
188 | 188 | $tableCreated = false; |
189 | 189 | if (!file_exists($this->SqliteDir . '/indexing')) { |
@@ -207,9 +207,11 @@ discard block |
||
207 | 207 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
208 | 208 | if (!isset($row['db'])) { |
209 | 209 | $db = 1; |
210 | - } elseif ($row['db'] <= 1) { |
|
210 | + } |
|
211 | + elseif ($row['db'] <= 1) { |
|
211 | 212 | $db = 1; |
212 | - } else { |
|
213 | + } |
|
214 | + else { |
|
213 | 215 | $db = $row['db']; |
214 | 216 | } |
215 | 217 | |
@@ -235,7 +237,8 @@ discard block |
||
235 | 237 | $row = $stm->fetch(PDO::FETCH_ASSOC); |
236 | 238 | if (isset($row['db']) && $row['db'] != '') { |
237 | 239 | $db = $row['db']; |
238 | - } else { |
|
240 | + } |
|
241 | + else { |
|
239 | 242 | /* |
240 | 243 | * Insert new to Indexing |
241 | 244 | */ |
@@ -256,8 +259,7 @@ discard block |
||
256 | 259 | * INIT Indexing DB |
257 | 260 | * @param PDO $db |
258 | 261 | */ |
259 | - public function initIndexing(PDO $db) |
|
260 | - { |
|
262 | + public function initIndexing(PDO $db) { |
|
261 | 263 | // delete everything before reset indexing |
262 | 264 | $dir = opendir($this->SqliteDir); |
263 | 265 | while ($file = readdir($dir)) { |
@@ -276,8 +278,7 @@ discard block |
||
276 | 278 | * INIT NEW DB |
277 | 279 | * @param PDO $db |
278 | 280 | */ |
279 | - public function initDB(PDO $db) |
|
280 | - { |
|
281 | + public function initDB(PDO $db) { |
|
281 | 282 | $db->exec('drop table if exists "caching"'); |
282 | 283 | $db->exec('CREATE TABLE "caching" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "keyword" VARCHAR UNIQUE, "object" BLOB, "exp" INTEGER)'); |
283 | 284 | $db->exec('CREATE UNIQUE INDEX "cleanup" ON "caching" ("keyword","exp")'); |
@@ -308,7 +309,8 @@ discard block |
||
308 | 309 | ); |
309 | 310 | |
310 | 311 | return true; |
311 | - } catch (PDOException $e) { |
|
312 | + } |
|
313 | + catch (PDOException $e) { |
|
312 | 314 | return false; |
313 | 315 | } |
314 | 316 | } |
@@ -337,10 +339,12 @@ discard block |
||
337 | 339 | ':U' => time(), |
338 | 340 | ] |
339 | 341 | ); |
340 | - } catch (PDOException $e) { |
|
342 | + } |
|
343 | + catch (PDOException $e) { |
|
341 | 344 | return false; |
342 | 345 | } |
343 | - } else { |
|
346 | + } |
|
347 | + else { |
|
344 | 348 | throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
345 | 349 | } |
346 | 350 | } |
@@ -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(WincacheDriver $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 WincacheDriver) { |
|
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(WincacheDriver $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 WincacheDriver) { |
|
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(WincacheDriver $driver, $key) |
|
41 | - { |
|
40 | + public function __construct(WincacheDriver $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 WincacheDriver) { |
53 | 51 | $this->driver = $driver; |
54 | 52 |
@@ -32,99 +32,99 @@ |
||
32 | 32 | */ |
33 | 33 | class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface |
34 | 34 | { |
35 | - use DriverBaseTrait; |
|
36 | - |
|
37 | - /** |
|
38 | - * @return bool |
|
39 | - */ |
|
40 | - public function driverCheck(): bool |
|
41 | - { |
|
42 | - return extension_loaded('wincache') && function_exists('wincache_ucache_set'); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @return DriverStatistic |
|
47 | - */ |
|
48 | - public function getStats(): DriverStatistic |
|
49 | - { |
|
50 | - $memInfo = wincache_ucache_meminfo(); |
|
51 | - $info = wincache_ucache_info(); |
|
52 | - $date = (new DateTime())->setTimestamp(time() - $info['total_cache_uptime']); |
|
53 | - |
|
54 | - return (new DriverStatistic()) |
|
55 | - ->setInfo(sprintf("The Wincache daemon is up since %s.\n For more information see RawData.", $date->format(DATE_RFC2822))) |
|
56 | - ->setSize($memInfo['memory_free'] - $memInfo['memory_total']) |
|
57 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
58 | - ->setRawData($memInfo); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - protected function driverConnect(): bool |
|
65 | - { |
|
66 | - return true; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @param CacheItemInterface $item |
|
71 | - * @return null|array |
|
72 | - */ |
|
73 | - protected function driverRead(CacheItemInterface $item) |
|
74 | - { |
|
75 | - $val = wincache_ucache_get($item->getKey(), $suc); |
|
76 | - |
|
77 | - if ($suc === false) { |
|
78 | - return null; |
|
79 | - } |
|
80 | - |
|
81 | - return $val; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @param CacheItemInterface $item |
|
86 | - * @return mixed |
|
87 | - * @throws PhpfastcacheInvalidArgumentException |
|
88 | - */ |
|
89 | - protected function driverWrite(CacheItemInterface $item): bool |
|
90 | - { |
|
91 | - /** |
|
92 | - * Check for Cross-Driver type confusion |
|
93 | - */ |
|
94 | - if ($item instanceof Item) { |
|
95 | - return wincache_ucache_set($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); |
|
96 | - } |
|
97 | - |
|
98 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param CacheItemInterface $item |
|
103 | - * @return bool |
|
104 | - * @throws PhpfastcacheInvalidArgumentException |
|
105 | - */ |
|
106 | - protected function driverDelete(CacheItemInterface $item): bool |
|
107 | - { |
|
108 | - /** |
|
109 | - * Check for Cross-Driver type confusion |
|
110 | - */ |
|
111 | - if ($item instanceof Item) { |
|
112 | - return wincache_ucache_delete($item->getKey()); |
|
113 | - } |
|
114 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
115 | - } |
|
116 | - |
|
117 | - /******************** |
|
35 | + use DriverBaseTrait; |
|
36 | + |
|
37 | + /** |
|
38 | + * @return bool |
|
39 | + */ |
|
40 | + public function driverCheck(): bool |
|
41 | + { |
|
42 | + return extension_loaded('wincache') && function_exists('wincache_ucache_set'); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @return DriverStatistic |
|
47 | + */ |
|
48 | + public function getStats(): DriverStatistic |
|
49 | + { |
|
50 | + $memInfo = wincache_ucache_meminfo(); |
|
51 | + $info = wincache_ucache_info(); |
|
52 | + $date = (new DateTime())->setTimestamp(time() - $info['total_cache_uptime']); |
|
53 | + |
|
54 | + return (new DriverStatistic()) |
|
55 | + ->setInfo(sprintf("The Wincache daemon is up since %s.\n For more information see RawData.", $date->format(DATE_RFC2822))) |
|
56 | + ->setSize($memInfo['memory_free'] - $memInfo['memory_total']) |
|
57 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
58 | + ->setRawData($memInfo); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + protected function driverConnect(): bool |
|
65 | + { |
|
66 | + return true; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @param CacheItemInterface $item |
|
71 | + * @return null|array |
|
72 | + */ |
|
73 | + protected function driverRead(CacheItemInterface $item) |
|
74 | + { |
|
75 | + $val = wincache_ucache_get($item->getKey(), $suc); |
|
76 | + |
|
77 | + if ($suc === false) { |
|
78 | + return null; |
|
79 | + } |
|
80 | + |
|
81 | + return $val; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @param CacheItemInterface $item |
|
86 | + * @return mixed |
|
87 | + * @throws PhpfastcacheInvalidArgumentException |
|
88 | + */ |
|
89 | + protected function driverWrite(CacheItemInterface $item): bool |
|
90 | + { |
|
91 | + /** |
|
92 | + * Check for Cross-Driver type confusion |
|
93 | + */ |
|
94 | + if ($item instanceof Item) { |
|
95 | + return wincache_ucache_set($item->getKey(), $this->driverPreWrap($item), $item->getTtl()); |
|
96 | + } |
|
97 | + |
|
98 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param CacheItemInterface $item |
|
103 | + * @return bool |
|
104 | + * @throws PhpfastcacheInvalidArgumentException |
|
105 | + */ |
|
106 | + protected function driverDelete(CacheItemInterface $item): bool |
|
107 | + { |
|
108 | + /** |
|
109 | + * Check for Cross-Driver type confusion |
|
110 | + */ |
|
111 | + if ($item instanceof Item) { |
|
112 | + return wincache_ucache_delete($item->getKey()); |
|
113 | + } |
|
114 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
115 | + } |
|
116 | + |
|
117 | + /******************** |
|
118 | 118 | * |
119 | 119 | * PSR-6 Extended Methods |
120 | 120 | * |
121 | 121 | *******************/ |
122 | 122 | |
123 | - /** |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - protected function driverClear(): bool |
|
127 | - { |
|
128 | - return wincache_ucache_clear(); |
|
129 | - } |
|
123 | + /** |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + protected function driverClear(): bool |
|
127 | + { |
|
128 | + return wincache_ucache_clear(); |
|
129 | + } |
|
130 | 130 | } |
@@ -70,8 +70,7 @@ |
||
70 | 70 | * @param CacheItemInterface $item |
71 | 71 | * @return null|array |
72 | 72 | */ |
73 | - protected function driverRead(CacheItemInterface $item) |
|
74 | - { |
|
73 | + protected function driverRead(CacheItemInterface $item) { |
|
75 | 74 | $val = wincache_ucache_get($item->getKey(), $suc); |
76 | 75 | |
77 | 76 | if ($suc === false) { |
@@ -20,257 +20,257 @@ |
||
20 | 20 | |
21 | 21 | class Config extends ConfigurationOption |
22 | 22 | { |
23 | - /** |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $host = '127.0.0.1'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var int |
|
30 | - */ |
|
31 | - protected $port = 27017; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var int |
|
35 | - */ |
|
36 | - protected $timeout = 3; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $username = ''; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $password = ''; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array |
|
50 | - */ |
|
51 | - protected $servers = []; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $collectionName = 'phpfastcache'; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var string |
|
60 | - */ |
|
61 | - protected $databaseName = Driver::MONGODB_DEFAULT_DB_NAME; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var array |
|
65 | - */ |
|
66 | - protected $options = []; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var array |
|
70 | - */ |
|
71 | - protected $driverOptions = []; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - protected $protocol = 'mongodb'; |
|
77 | - |
|
78 | - /** |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getHost(): string |
|
82 | - { |
|
83 | - return $this->host; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $host |
|
88 | - * @return self |
|
89 | - */ |
|
90 | - public function setHost(string $host): self |
|
91 | - { |
|
92 | - $this->host = $host; |
|
93 | - return $this; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return int |
|
98 | - */ |
|
99 | - public function getPort(): int |
|
100 | - { |
|
101 | - return $this->port; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @param int $port |
|
106 | - * @return self |
|
107 | - */ |
|
108 | - public function setPort(int $port): self |
|
109 | - { |
|
110 | - $this->port = $port; |
|
111 | - return $this; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @return int |
|
116 | - */ |
|
117 | - public function getTimeout(): int |
|
118 | - { |
|
119 | - return $this->timeout; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @param int $timeout |
|
124 | - * @return self |
|
125 | - */ |
|
126 | - public function setTimeout(int $timeout): self |
|
127 | - { |
|
128 | - $this->timeout = $timeout; |
|
129 | - return $this; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function getUsername(): string |
|
136 | - { |
|
137 | - return $this->username; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $username |
|
142 | - * @return self |
|
143 | - */ |
|
144 | - public function setUsername(string $username): self |
|
145 | - { |
|
146 | - $this->username = $username; |
|
147 | - return $this; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return string |
|
152 | - */ |
|
153 | - public function getPassword(): string |
|
154 | - { |
|
155 | - return $this->password; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param string $password |
|
160 | - * @return self |
|
161 | - */ |
|
162 | - public function setPassword(string $password): self |
|
163 | - { |
|
164 | - $this->password = $password; |
|
165 | - return $this; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return array |
|
170 | - */ |
|
171 | - public function getServers(): array |
|
172 | - { |
|
173 | - return $this->servers; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * @param array $servers |
|
178 | - * @return self |
|
179 | - */ |
|
180 | - public function setServers(array $servers): self |
|
181 | - { |
|
182 | - $this->servers = $servers; |
|
183 | - return $this; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @return string |
|
188 | - */ |
|
189 | - public function getCollectionName(): string |
|
190 | - { |
|
191 | - return $this->collectionName; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param string $collectionName |
|
196 | - * @return self |
|
197 | - */ |
|
198 | - public function setCollectionName(string $collectionName): self |
|
199 | - { |
|
200 | - $this->collectionName = $collectionName; |
|
201 | - return $this; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function getDatabaseName(): string |
|
208 | - { |
|
209 | - return $this->databaseName; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * @param string $databaseName |
|
214 | - * @return self |
|
215 | - */ |
|
216 | - public function setDatabaseName(string $databaseName): self |
|
217 | - { |
|
218 | - $this->databaseName = $databaseName; |
|
219 | - return $this; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @return array |
|
224 | - */ |
|
225 | - public function getOptions(): array |
|
226 | - { |
|
227 | - return $this->options; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @see https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options |
|
232 | - * @param array $options |
|
233 | - * @return Config |
|
234 | - */ |
|
235 | - public function setOptions(array $options): self |
|
236 | - { |
|
237 | - $this->options = $options; |
|
238 | - return $this; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @return array |
|
243 | - */ |
|
244 | - public function getDriverOptions(): array |
|
245 | - { |
|
246 | - return $this->driverOptions; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @param array $driverOptions |
|
251 | - * @return self |
|
252 | - */ |
|
253 | - public function setDriverOptions(array $driverOptions): self |
|
254 | - { |
|
255 | - $this->driverOptions = $driverOptions; |
|
256 | - return $this; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @return string |
|
261 | - */ |
|
262 | - public function getProtocol(): string |
|
263 | - { |
|
264 | - return $this->protocol; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @param string $protocol |
|
269 | - * @return self |
|
270 | - */ |
|
271 | - public function setProtocol(string $protocol): self |
|
272 | - { |
|
273 | - $this->protocol = $protocol; |
|
274 | - return $this; |
|
275 | - } |
|
23 | + /** |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $host = '127.0.0.1'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var int |
|
30 | + */ |
|
31 | + protected $port = 27017; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var int |
|
35 | + */ |
|
36 | + protected $timeout = 3; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $username = ''; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $password = ''; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array |
|
50 | + */ |
|
51 | + protected $servers = []; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $collectionName = 'phpfastcache'; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var string |
|
60 | + */ |
|
61 | + protected $databaseName = Driver::MONGODB_DEFAULT_DB_NAME; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var array |
|
65 | + */ |
|
66 | + protected $options = []; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var array |
|
70 | + */ |
|
71 | + protected $driverOptions = []; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + protected $protocol = 'mongodb'; |
|
77 | + |
|
78 | + /** |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getHost(): string |
|
82 | + { |
|
83 | + return $this->host; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $host |
|
88 | + * @return self |
|
89 | + */ |
|
90 | + public function setHost(string $host): self |
|
91 | + { |
|
92 | + $this->host = $host; |
|
93 | + return $this; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return int |
|
98 | + */ |
|
99 | + public function getPort(): int |
|
100 | + { |
|
101 | + return $this->port; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @param int $port |
|
106 | + * @return self |
|
107 | + */ |
|
108 | + public function setPort(int $port): self |
|
109 | + { |
|
110 | + $this->port = $port; |
|
111 | + return $this; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @return int |
|
116 | + */ |
|
117 | + public function getTimeout(): int |
|
118 | + { |
|
119 | + return $this->timeout; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @param int $timeout |
|
124 | + * @return self |
|
125 | + */ |
|
126 | + public function setTimeout(int $timeout): self |
|
127 | + { |
|
128 | + $this->timeout = $timeout; |
|
129 | + return $this; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function getUsername(): string |
|
136 | + { |
|
137 | + return $this->username; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $username |
|
142 | + * @return self |
|
143 | + */ |
|
144 | + public function setUsername(string $username): self |
|
145 | + { |
|
146 | + $this->username = $username; |
|
147 | + return $this; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return string |
|
152 | + */ |
|
153 | + public function getPassword(): string |
|
154 | + { |
|
155 | + return $this->password; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param string $password |
|
160 | + * @return self |
|
161 | + */ |
|
162 | + public function setPassword(string $password): self |
|
163 | + { |
|
164 | + $this->password = $password; |
|
165 | + return $this; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return array |
|
170 | + */ |
|
171 | + public function getServers(): array |
|
172 | + { |
|
173 | + return $this->servers; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * @param array $servers |
|
178 | + * @return self |
|
179 | + */ |
|
180 | + public function setServers(array $servers): self |
|
181 | + { |
|
182 | + $this->servers = $servers; |
|
183 | + return $this; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @return string |
|
188 | + */ |
|
189 | + public function getCollectionName(): string |
|
190 | + { |
|
191 | + return $this->collectionName; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param string $collectionName |
|
196 | + * @return self |
|
197 | + */ |
|
198 | + public function setCollectionName(string $collectionName): self |
|
199 | + { |
|
200 | + $this->collectionName = $collectionName; |
|
201 | + return $this; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function getDatabaseName(): string |
|
208 | + { |
|
209 | + return $this->databaseName; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * @param string $databaseName |
|
214 | + * @return self |
|
215 | + */ |
|
216 | + public function setDatabaseName(string $databaseName): self |
|
217 | + { |
|
218 | + $this->databaseName = $databaseName; |
|
219 | + return $this; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @return array |
|
224 | + */ |
|
225 | + public function getOptions(): array |
|
226 | + { |
|
227 | + return $this->options; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @see https://docs.mongodb.com/manual/reference/connection-string/#connections-connection-options |
|
232 | + * @param array $options |
|
233 | + * @return Config |
|
234 | + */ |
|
235 | + public function setOptions(array $options): self |
|
236 | + { |
|
237 | + $this->options = $options; |
|
238 | + return $this; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @return array |
|
243 | + */ |
|
244 | + public function getDriverOptions(): array |
|
245 | + { |
|
246 | + return $this->driverOptions; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @param array $driverOptions |
|
251 | + * @return self |
|
252 | + */ |
|
253 | + public function setDriverOptions(array $driverOptions): self |
|
254 | + { |
|
255 | + $this->driverOptions = $driverOptions; |
|
256 | + return $this; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @return string |
|
261 | + */ |
|
262 | + public function getProtocol(): string |
|
263 | + { |
|
264 | + return $this->protocol; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @param string $protocol |
|
269 | + * @return self |
|
270 | + */ |
|
271 | + public function setProtocol(string $protocol): self |
|
272 | + { |
|
273 | + $this->protocol = $protocol; |
|
274 | + return $this; |
|
275 | + } |
|
276 | 276 | } |
@@ -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(MongodbDriver $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 MongodbDriver) { |
|
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(MongodbDriver $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 MongodbDriver) { |
|
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(MongodbDriver $driver, $key) |
|
41 | - { |
|
40 | + public function __construct(MongodbDriver $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 MongodbDriver) { |
53 | 51 | $this->driver = $driver; |
54 | 52 |
@@ -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(DevtrueDriver $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 DevtrueDriver) { |
|
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(DevtrueDriver $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 DevtrueDriver) { |
|
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(DevtrueDriver $driver, $key) |
|
41 | - { |
|
40 | + public function __construct(DevtrueDriver $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 DevtrueDriver) { |
53 | 51 | $this->driver = $driver; |
54 | 52 |
@@ -31,96 +31,96 @@ |
||
31 | 31 | */ |
32 | 32 | class Driver implements ExtendedCacheItemPoolInterface |
33 | 33 | { |
34 | - use DriverBaseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @return bool |
|
38 | - */ |
|
39 | - public function driverCheck(): bool |
|
40 | - { |
|
41 | - return true; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @return DriverStatistic |
|
46 | - */ |
|
47 | - public function getStats(): DriverStatistic |
|
48 | - { |
|
49 | - $stat = new DriverStatistic(); |
|
50 | - $stat->setInfo('[Devtrue] A void info string') |
|
51 | - ->setSize(0) |
|
52 | - ->setData(implode(', ', array_keys($this->itemInstances))) |
|
53 | - ->setRawData(true); |
|
54 | - |
|
55 | - return $stat; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param CacheItemInterface $item |
|
60 | - * @return mixed |
|
61 | - * @throws PhpfastcacheInvalidArgumentException |
|
62 | - */ |
|
63 | - protected function driverWrite(CacheItemInterface $item): bool |
|
64 | - { |
|
65 | - /** |
|
66 | - * Check for Cross-Driver type confusion |
|
67 | - */ |
|
68 | - if ($item instanceof Item) { |
|
69 | - return false; |
|
70 | - } |
|
71 | - |
|
72 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @param CacheItemInterface $item |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - protected function driverRead(CacheItemInterface $item): array |
|
80 | - { |
|
81 | - return [ |
|
82 | - self::DRIVER_DATA_WRAPPER_INDEX => true, |
|
83 | - self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
84 | - self::DRIVER_EDATE_WRAPPER_INDEX => new DateTime(), |
|
85 | - ]; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @param CacheItemInterface $item |
|
90 | - * @return bool |
|
91 | - * @throws PhpfastcacheInvalidArgumentException |
|
92 | - */ |
|
93 | - protected function driverDelete(CacheItemInterface $item): bool |
|
94 | - { |
|
95 | - /** |
|
96 | - * Check for Cross-Driver type confusion |
|
97 | - */ |
|
98 | - if ($item instanceof Item) { |
|
99 | - return false; |
|
100 | - } |
|
101 | - |
|
102 | - throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - protected function driverClear(): bool |
|
109 | - { |
|
110 | - return false; |
|
111 | - } |
|
112 | - |
|
113 | - /******************** |
|
34 | + use DriverBaseTrait; |
|
35 | + |
|
36 | + /** |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | + public function driverCheck(): bool |
|
40 | + { |
|
41 | + return true; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @return DriverStatistic |
|
46 | + */ |
|
47 | + public function getStats(): DriverStatistic |
|
48 | + { |
|
49 | + $stat = new DriverStatistic(); |
|
50 | + $stat->setInfo('[Devtrue] A void info string') |
|
51 | + ->setSize(0) |
|
52 | + ->setData(implode(', ', array_keys($this->itemInstances))) |
|
53 | + ->setRawData(true); |
|
54 | + |
|
55 | + return $stat; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param CacheItemInterface $item |
|
60 | + * @return mixed |
|
61 | + * @throws PhpfastcacheInvalidArgumentException |
|
62 | + */ |
|
63 | + protected function driverWrite(CacheItemInterface $item): bool |
|
64 | + { |
|
65 | + /** |
|
66 | + * Check for Cross-Driver type confusion |
|
67 | + */ |
|
68 | + if ($item instanceof Item) { |
|
69 | + return false; |
|
70 | + } |
|
71 | + |
|
72 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @param CacheItemInterface $item |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + protected function driverRead(CacheItemInterface $item): array |
|
80 | + { |
|
81 | + return [ |
|
82 | + self::DRIVER_DATA_WRAPPER_INDEX => true, |
|
83 | + self::DRIVER_TAGS_WRAPPER_INDEX => [], |
|
84 | + self::DRIVER_EDATE_WRAPPER_INDEX => new DateTime(), |
|
85 | + ]; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @param CacheItemInterface $item |
|
90 | + * @return bool |
|
91 | + * @throws PhpfastcacheInvalidArgumentException |
|
92 | + */ |
|
93 | + protected function driverDelete(CacheItemInterface $item): bool |
|
94 | + { |
|
95 | + /** |
|
96 | + * Check for Cross-Driver type confusion |
|
97 | + */ |
|
98 | + if ($item instanceof Item) { |
|
99 | + return false; |
|
100 | + } |
|
101 | + |
|
102 | + throw new PhpfastcacheInvalidArgumentException('Cross-Driver type confusion detected'); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + protected function driverClear(): bool |
|
109 | + { |
|
110 | + return false; |
|
111 | + } |
|
112 | + |
|
113 | + /******************** |
|
114 | 114 | * |
115 | 115 | * PSR-6 Extended Methods |
116 | 116 | * |
117 | 117 | *******************/ |
118 | 118 | |
119 | - /** |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - protected function driverConnect(): bool |
|
123 | - { |
|
124 | - return false; |
|
125 | - } |
|
119 | + /** |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + protected function driverConnect(): bool |
|
123 | + { |
|
124 | + return false; |
|
125 | + } |
|
126 | 126 | } |
127 | 127 | \ No newline at end of file |