Test Failed
Push — master ( 6ab057...9e2699 )
by
unknown
23:26 queued 12:21
created
phpfastcache/lib/Phpfastcache/Core/Item/ExtendedCacheItemTrait.php 3 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -26,282 +26,282 @@
 block discarded – undo
26 26
 
27 27
 trait ExtendedCacheItemTrait
28 28
 {
29
-    use CacheItemTrait;
30
-
31
-    protected ExtendedCacheItemPoolInterface $driver;
32
-
33
-    protected string $encodedKey;
34
-
35
-    /**
36
-     * Item constructor.
37
-     * @param ExtendedCacheItemPoolInterface $driver
38
-     * @param string $key
39
-     * @param EventManagerInterface $em
40
-     * @throws PhpfastcacheInvalidArgumentException
41
-     */
42
-    public function __construct(ExtendedCacheItemPoolInterface $driver, string $key, EventManagerInterface $em)
43
-    {
44
-        $this->data = null;
45
-        $this->key = $key;
46
-        $this->setEventManager($em);
47
-        $this->setDriver($driver);
48
-        if ($driver->getConfig()->isUseStaticItemCaching()) {
49
-            $this->driver->setItem($this);
50
-        }
51
-        $this->expirationDate = new DateTime();
52
-        if ($this->driver->getConfig()->isItemDetailedDate()) {
53
-            $this->creationDate = new DateTime();
54
-            $this->modificationDate = new DateTime();
55
-        }
56
-    }
57
-
58
-    /**
59
-     * @param ExtendedCacheItemPoolInterface $driver
60
-     * @return ExtendedCacheItemInterface
61
-     * @throws PhpfastcacheInvalidArgumentException
62
-     */
63
-    public function setDriver(ExtendedCacheItemPoolInterface $driver): ExtendedCacheItemInterface
64
-    {
65
-        $driverClass = $this->getDriverClass();
66
-        if ($driver instanceof $driverClass) {
67
-            $this->driver = $driver;
68
-
69
-            return $this;
70
-        }
71
-
72
-        throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid driver instance "%s" for cache item "%s"', $driver::class, static::class));
73
-    }
74
-
75
-    /**
76
-     * @inheritDoc
77
-     */
78
-    public function getEncodedKey(): string
79
-    {
80
-        if (!isset($this->encodedKey)) {
81
-            $this->encodedKey = $this->driver->getEncodedKey($this->getKey());
82
-        }
83
-
84
-        return $this->encodedKey;
85
-    }
86
-
87
-    /**
88
-     * @inheritDoc
89
-     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
90
-     */
91
-    public function _getData(): mixed // @phpcs:ignore
92
-    {
93
-        return $this->data;
94
-    }
95
-
96
-    /**
97
-     * @inheritDoc
98
-     */
99
-    public function getExpirationDate(): DateTimeInterface
100
-    {
101
-        return $this->expirationDate;
102
-    }
103
-
104
-    /**
105
-     * @inheritDoc
106
-     * @throws PhpfastcacheInvalidArgumentException
107
-     */
108
-    public function setExpirationDate(DateTimeInterface $expiration): ExtendedCacheItemInterface
109
-    {
110
-        return $this->expiresAt($expiration);
111
-    }
112
-
113
-    /**
114
-     * @inheritDoc
115
-     * @throws PhpfastcacheLogicException
116
-     */
117
-    public function getCreationDate(): DateTimeInterface
118
-    {
119
-        if ($this->driver->getConfig()->isItemDetailedDate()) {
120
-            return $this->creationDate;
121
-        }
122
-
123
-        throw new PhpfastcacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
124
-    }
125
-
126
-    /**
127
-     * @inheritDoc
128
-     * @throws PhpfastcacheLogicException
129
-     */
130
-    public function setCreationDate(DateTimeInterface $date): ExtendedCacheItemInterface
131
-    {
132
-        if ($this->driver->getConfig()->isItemDetailedDate()) {
133
-            $this->creationDate = $this->demutateDatetime($date);
134
-            return $this;
135
-        }
136
-
137
-        throw new PhpfastcacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
138
-    }
139
-
140
-    /**
141
-     * @inheritDoc
142
-     * @throws PhpfastcacheLogicException
143
-     */
144
-    public function getModificationDate(): DateTimeInterface
145
-    {
146
-        if ($this->driver->getConfig()->isItemDetailedDate()) {
147
-            return $this->modificationDate;
148
-        }
149
-
150
-        throw new PhpfastcacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
151
-    }
152
-
153
-    /**
154
-     * @inheritDoc
155
-     * @throws PhpfastcacheLogicException
156
-     */
157
-    public function setModificationDate(DateTimeInterface $date): ExtendedCacheItemInterface
158
-    {
159
-        if ($this->driver->getConfig()->isItemDetailedDate()) {
160
-            $this->modificationDate = $this->demutateDatetime($date);
161
-            return $this;
162
-        }
163
-
164
-        throw new PhpfastcacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
165
-    }
166
-
167
-    public function getTtl(): int
168
-    {
169
-        return \max(0, $this->expirationDate->getTimestamp() - \time());
170
-    }
171
-
172
-    public function isExpired(): bool
173
-    {
174
-        return $this->getTtl() <= 0;
175
-    }
176
-
177
-    public function isNull(): bool
178
-    {
179
-        return $this->get() === null;
180
-    }
181
-
182
-    public function isEmpty(): bool
183
-    {
184
-        return empty($this->get());
185
-    }
186
-
187
-    /**
188
-     * Return the data length:
189
-     * Either the string length if it's a string (binary mode)
190
-     * # or the number of element (count) if it's an array
191
-     * # or the number returned by count() if it's an object implementing \Countable interface
192
-     * # -1 for anything else
193
-     * @return int
194
-     */
195
-    public function getLength(): int
196
-    {
197
-        switch (\gettype($this->data)) {
198
-            case 'array':
199
-            case 'object':
200
-                if (\is_countable($this->data)) {
201
-                    return \count($this->data);
202
-                }
203
-                break;
204
-
205
-            case 'string':
206
-                return \strlen($this->data);
207
-        }
208
-
209
-        return -1;
210
-    }
211
-
212
-    /**
213
-     * @throws PhpfastcacheInvalidTypeException
214
-     */
215
-    public function increment(int $step = 1): ExtendedCacheItemInterface
216
-    {
217
-        if ($this->data !== null && !\is_numeric($this->data)) {
218
-            throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot increment on a "%s" type.', \gettype($this->data)));
219
-        }
220
-
221
-        $this->data += $step;
222
-
223
-        return $this;
224
-    }
225
-
226
-    /**
227
-     * @throws PhpfastcacheInvalidTypeException
228
-     */
229
-    public function decrement(int $step = 1): ExtendedCacheItemInterface
230
-    {
231
-        if ($this->data !== null && !\is_numeric($this->data)) {
232
-            throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot decrement on a "%s" type.', \gettype($this->data)));
233
-        }
234
-
235
-        $this->data -= $step;
236
-
237
-        return $this;
238
-    }
239
-
240
-    /**
241
-     * @throws PhpfastcacheInvalidTypeException
242
-     */
243
-    public function append(array|string $data): ExtendedCacheItemInterface
244
-    {
245
-        if ($this->data !== null && !\is_string($this->data) && !\is_array($this->data)) {
246
-            throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot append on a "%s" type.', \gettype($this->data)));
247
-        }
248
-
249
-        if (\is_array($this->data)) {
250
-            $this->data[] = $data;
251
-        } else {
252
-            $this->data .= $data;
253
-        }
254
-
255
-        return $this;
256
-    }
257
-
258
-    /**
259
-     * @throws PhpfastcacheInvalidTypeException
260
-     */
261
-    public function prepend(array|string $data): ExtendedCacheItemInterface
262
-    {
263
-        if ($this->data !== null && !\is_string($this->data) && !\is_array($this->data)) {
264
-            throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot prepend on a "%s" type.', \gettype($this->data)));
265
-        }
266
-
267
-        if (\is_array($this->data)) {
268
-            \array_unshift($this->data, $data);
269
-        } else {
270
-            $this->data = $data . $this->data;
271
-        }
272
-
273
-        return $this;
274
-    }
275
-
276
-    /**
277
-     * Return the data as a well-formatted string.
278
-     * Any scalar value will be cast to an array
279
-     * @param int $options \json_encode() options
280
-     * @param int $depth \json_encode() depth
281
-     * @return string
282
-     */
283
-    public function getDataAsJsonString(int $options = JSON_THROW_ON_ERROR, int $depth = 512): string
284
-    {
285
-        $data = $this->get();
286
-
287
-        if (\is_object($data) || \is_array($data)) {
288
-            $data = \json_encode($data, $options, $depth);
289
-        } else {
290
-            $data = \json_encode([$data], $options, $depth);
291
-        }
292
-
293
-        return \json_encode($data, $options, $depth);
294
-    }
295
-
296
-    public function jsonSerialize(): mixed
297
-    {
298
-        return $this->get();
299
-    }
300
-
301
-    public function doesItemBelongToThatDriverBackend(ExtendedCacheItemPoolInterface $driverPool): bool
302
-    {
303
-        return $driverPool::getClassNamespace() === self::getClassNamespace();
304
-    }
305
-
306
-    abstract protected function getDriverClass(): string;
29
+	use CacheItemTrait;
30
+
31
+	protected ExtendedCacheItemPoolInterface $driver;
32
+
33
+	protected string $encodedKey;
34
+
35
+	/**
36
+	 * Item constructor.
37
+	 * @param ExtendedCacheItemPoolInterface $driver
38
+	 * @param string $key
39
+	 * @param EventManagerInterface $em
40
+	 * @throws PhpfastcacheInvalidArgumentException
41
+	 */
42
+	public function __construct(ExtendedCacheItemPoolInterface $driver, string $key, EventManagerInterface $em)
43
+	{
44
+		$this->data = null;
45
+		$this->key = $key;
46
+		$this->setEventManager($em);
47
+		$this->setDriver($driver);
48
+		if ($driver->getConfig()->isUseStaticItemCaching()) {
49
+			$this->driver->setItem($this);
50
+		}
51
+		$this->expirationDate = new DateTime();
52
+		if ($this->driver->getConfig()->isItemDetailedDate()) {
53
+			$this->creationDate = new DateTime();
54
+			$this->modificationDate = new DateTime();
55
+		}
56
+	}
57
+
58
+	/**
59
+	 * @param ExtendedCacheItemPoolInterface $driver
60
+	 * @return ExtendedCacheItemInterface
61
+	 * @throws PhpfastcacheInvalidArgumentException
62
+	 */
63
+	public function setDriver(ExtendedCacheItemPoolInterface $driver): ExtendedCacheItemInterface
64
+	{
65
+		$driverClass = $this->getDriverClass();
66
+		if ($driver instanceof $driverClass) {
67
+			$this->driver = $driver;
68
+
69
+			return $this;
70
+		}
71
+
72
+		throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid driver instance "%s" for cache item "%s"', $driver::class, static::class));
73
+	}
74
+
75
+	/**
76
+	 * @inheritDoc
77
+	 */
78
+	public function getEncodedKey(): string
79
+	{
80
+		if (!isset($this->encodedKey)) {
81
+			$this->encodedKey = $this->driver->getEncodedKey($this->getKey());
82
+		}
83
+
84
+		return $this->encodedKey;
85
+	}
86
+
87
+	/**
88
+	 * @inheritDoc
89
+	 * @SuppressWarnings(PHPMD.CamelCaseMethodName)
90
+	 */
91
+	public function _getData(): mixed // @phpcs:ignore
92
+	{
93
+		return $this->data;
94
+	}
95
+
96
+	/**
97
+	 * @inheritDoc
98
+	 */
99
+	public function getExpirationDate(): DateTimeInterface
100
+	{
101
+		return $this->expirationDate;
102
+	}
103
+
104
+	/**
105
+	 * @inheritDoc
106
+	 * @throws PhpfastcacheInvalidArgumentException
107
+	 */
108
+	public function setExpirationDate(DateTimeInterface $expiration): ExtendedCacheItemInterface
109
+	{
110
+		return $this->expiresAt($expiration);
111
+	}
112
+
113
+	/**
114
+	 * @inheritDoc
115
+	 * @throws PhpfastcacheLogicException
116
+	 */
117
+	public function getCreationDate(): DateTimeInterface
118
+	{
119
+		if ($this->driver->getConfig()->isItemDetailedDate()) {
120
+			return $this->creationDate;
121
+		}
122
+
123
+		throw new PhpfastcacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
124
+	}
125
+
126
+	/**
127
+	 * @inheritDoc
128
+	 * @throws PhpfastcacheLogicException
129
+	 */
130
+	public function setCreationDate(DateTimeInterface $date): ExtendedCacheItemInterface
131
+	{
132
+		if ($this->driver->getConfig()->isItemDetailedDate()) {
133
+			$this->creationDate = $this->demutateDatetime($date);
134
+			return $this;
135
+		}
136
+
137
+		throw new PhpfastcacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
138
+	}
139
+
140
+	/**
141
+	 * @inheritDoc
142
+	 * @throws PhpfastcacheLogicException
143
+	 */
144
+	public function getModificationDate(): DateTimeInterface
145
+	{
146
+		if ($this->driver->getConfig()->isItemDetailedDate()) {
147
+			return $this->modificationDate;
148
+		}
149
+
150
+		throw new PhpfastcacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
151
+	}
152
+
153
+	/**
154
+	 * @inheritDoc
155
+	 * @throws PhpfastcacheLogicException
156
+	 */
157
+	public function setModificationDate(DateTimeInterface $date): ExtendedCacheItemInterface
158
+	{
159
+		if ($this->driver->getConfig()->isItemDetailedDate()) {
160
+			$this->modificationDate = $this->demutateDatetime($date);
161
+			return $this;
162
+		}
163
+
164
+		throw new PhpfastcacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
165
+	}
166
+
167
+	public function getTtl(): int
168
+	{
169
+		return \max(0, $this->expirationDate->getTimestamp() - \time());
170
+	}
171
+
172
+	public function isExpired(): bool
173
+	{
174
+		return $this->getTtl() <= 0;
175
+	}
176
+
177
+	public function isNull(): bool
178
+	{
179
+		return $this->get() === null;
180
+	}
181
+
182
+	public function isEmpty(): bool
183
+	{
184
+		return empty($this->get());
185
+	}
186
+
187
+	/**
188
+	 * Return the data length:
189
+	 * Either the string length if it's a string (binary mode)
190
+	 * # or the number of element (count) if it's an array
191
+	 * # or the number returned by count() if it's an object implementing \Countable interface
192
+	 * # -1 for anything else
193
+	 * @return int
194
+	 */
195
+	public function getLength(): int
196
+	{
197
+		switch (\gettype($this->data)) {
198
+			case 'array':
199
+			case 'object':
200
+				if (\is_countable($this->data)) {
201
+					return \count($this->data);
202
+				}
203
+				break;
204
+
205
+			case 'string':
206
+				return \strlen($this->data);
207
+		}
208
+
209
+		return -1;
210
+	}
211
+
212
+	/**
213
+	 * @throws PhpfastcacheInvalidTypeException
214
+	 */
215
+	public function increment(int $step = 1): ExtendedCacheItemInterface
216
+	{
217
+		if ($this->data !== null && !\is_numeric($this->data)) {
218
+			throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot increment on a "%s" type.', \gettype($this->data)));
219
+		}
220
+
221
+		$this->data += $step;
222
+
223
+		return $this;
224
+	}
225
+
226
+	/**
227
+	 * @throws PhpfastcacheInvalidTypeException
228
+	 */
229
+	public function decrement(int $step = 1): ExtendedCacheItemInterface
230
+	{
231
+		if ($this->data !== null && !\is_numeric($this->data)) {
232
+			throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot decrement on a "%s" type.', \gettype($this->data)));
233
+		}
234
+
235
+		$this->data -= $step;
236
+
237
+		return $this;
238
+	}
239
+
240
+	/**
241
+	 * @throws PhpfastcacheInvalidTypeException
242
+	 */
243
+	public function append(array|string $data): ExtendedCacheItemInterface
244
+	{
245
+		if ($this->data !== null && !\is_string($this->data) && !\is_array($this->data)) {
246
+			throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot append on a "%s" type.', \gettype($this->data)));
247
+		}
248
+
249
+		if (\is_array($this->data)) {
250
+			$this->data[] = $data;
251
+		} else {
252
+			$this->data .= $data;
253
+		}
254
+
255
+		return $this;
256
+	}
257
+
258
+	/**
259
+	 * @throws PhpfastcacheInvalidTypeException
260
+	 */
261
+	public function prepend(array|string $data): ExtendedCacheItemInterface
262
+	{
263
+		if ($this->data !== null && !\is_string($this->data) && !\is_array($this->data)) {
264
+			throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot prepend on a "%s" type.', \gettype($this->data)));
265
+		}
266
+
267
+		if (\is_array($this->data)) {
268
+			\array_unshift($this->data, $data);
269
+		} else {
270
+			$this->data = $data . $this->data;
271
+		}
272
+
273
+		return $this;
274
+	}
275
+
276
+	/**
277
+	 * Return the data as a well-formatted string.
278
+	 * Any scalar value will be cast to an array
279
+	 * @param int $options \json_encode() options
280
+	 * @param int $depth \json_encode() depth
281
+	 * @return string
282
+	 */
283
+	public function getDataAsJsonString(int $options = JSON_THROW_ON_ERROR, int $depth = 512): string
284
+	{
285
+		$data = $this->get();
286
+
287
+		if (\is_object($data) || \is_array($data)) {
288
+			$data = \json_encode($data, $options, $depth);
289
+		} else {
290
+			$data = \json_encode([$data], $options, $depth);
291
+		}
292
+
293
+		return \json_encode($data, $options, $depth);
294
+	}
295
+
296
+	public function jsonSerialize(): mixed
297
+	{
298
+		return $this->get();
299
+	}
300
+
301
+	public function doesItemBelongToThatDriverBackend(ExtendedCacheItemPoolInterface $driverPool): bool
302
+	{
303
+		return $driverPool::getClassNamespace() === self::getClassNamespace();
304
+	}
305
+
306
+	abstract protected function getDriverClass(): string;
307 307
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     /**
241 241
      * @throws PhpfastcacheInvalidTypeException
242 242
      */
243
-    public function append(array|string $data): ExtendedCacheItemInterface
243
+    public function append(array | string $data): ExtendedCacheItemInterface
244 244
     {
245 245
         if ($this->data !== null && !\is_string($this->data) && !\is_array($this->data)) {
246 246
             throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot append on a "%s" type.', \gettype($this->data)));
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     /**
259 259
      * @throws PhpfastcacheInvalidTypeException
260 260
      */
261
-    public function prepend(array|string $data): ExtendedCacheItemInterface
261
+    public function prepend(array | string $data): ExtendedCacheItemInterface
262 262
     {
263 263
         if ($this->data !== null && !\is_string($this->data) && !\is_array($this->data)) {
264 264
             throw new PhpfastcacheInvalidTypeException(\sprintf('Cannot prepend on a "%s" type.', \gettype($this->data)));
Please login to merge, or discard this patch.
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,8 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param EventManagerInterface $em
40 40
      * @throws PhpfastcacheInvalidArgumentException
41 41
      */
42
-    public function __construct(ExtendedCacheItemPoolInterface $driver, string $key, EventManagerInterface $em)
43
-    {
42
+    public function __construct(ExtendedCacheItemPoolInterface $driver, string $key, EventManagerInterface $em) {
44 43
         $this->data = null;
45 44
         $this->key = $key;
46 45
         $this->setEventManager($em);
@@ -248,7 +247,8 @@  discard block
 block discarded – undo
248 247
 
249 248
         if (\is_array($this->data)) {
250 249
             $this->data[] = $data;
251
-        } else {
250
+        }
251
+        else {
252 252
             $this->data .= $data;
253 253
         }
254 254
 
@@ -266,7 +266,8 @@  discard block
 block discarded – undo
266 266
 
267 267
         if (\is_array($this->data)) {
268 268
             \array_unshift($this->data, $data);
269
-        } else {
269
+        }
270
+        else {
270 271
             $this->data = $data . $this->data;
271 272
         }
272 273
 
@@ -286,7 +287,8 @@  discard block
 block discarded – undo
286 287
 
287 288
         if (\is_object($data) || \is_array($data)) {
288 289
             $data = \json_encode($data, $options, $depth);
289
-        } else {
290
+        }
291
+        else {
290 292
             $data = \json_encode([$data], $options, $depth);
291 293
         }
292 294
 
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -27,181 +27,181 @@
 block discarded – undo
27 27
 use Psr\Cache\CacheItemInterface;
28 28
 
29 29
 interface ExtendedCacheItemInterface extends
30
-    CacheItemInterface,
31
-    EventManagerDispatcherInterface,
32
-    ClassNamespaceResolverInterface,
33
-    JsonSerializable,
34
-    TaggableCacheItemInterface
30
+	CacheItemInterface,
31
+	EventManagerDispatcherInterface,
32
+	ClassNamespaceResolverInterface,
33
+	JsonSerializable,
34
+	TaggableCacheItemInterface
35 35
 {
36
-    /**
37
-     * Returns the encoded key for the current cache item.
38
-     * Is a MD5 (default),SHA1,SHA256 hash if "defaultKeyHashFunction" config option is configured
39
-     * Else return the plain cache item key "defaultKeyHashFunction" config option is emptied
40
-     *
41
-     * @return string
42
-     *   The encoded key string for this cache item.
43
-     */
44
-    public function getEncodedKey(): string;
45
-
46
-    /**
47
-     * Returns the cache item value, regardless of hit status.
48
-     * This method can be called if the cache item is NOT YET
49
-     * persisted, and you need to access to its set value.
50
-     *
51
-     * Although not part of the CacheItemInterface, this method is used by
52
-     * the pool for extracting information for saving.
53
-     *
54
-     * @return mixed
55
-     *
56
-     * @internal This method is used internally by phpfastcache, so you should not use it in your application.
57
-     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
58
-     */
59
-    public function _getData(): mixed; // @phpcs:ignore
60
-
61
-    /**
62
-     * @return DateTimeInterface
63
-     */
64
-    public function getExpirationDate(): DateTimeInterface;
65
-
66
-    /**
67
-     * Alias of expireAt() with forced $expiration param
68
-     *
69
-     * @param DateTimeInterface $expiration
70
-     *   The point in time after which the item MUST be considered expired.
71
-     *   If null is passed explicitly, a default value MAY be used. If none is set,
72
-     *   the value should be stored permanently or for as long as the
73
-     *   implementation allows.
74
-     *
75
-     * @return ExtendedCacheItemInterface
76
-     *   The called object.
77
-     */
78
-    public function setExpirationDate(DateTimeInterface $expiration): ExtendedCacheItemInterface;
79
-
80
-    /**
81
-     * @return DateTimeInterface
82
-     * @throws PhpfastcacheLogicException
83
-     */
84
-    public function getCreationDate(): DateTimeInterface;
85
-
86
-    /**
87
-     * @return DateTimeInterface
88
-     * @throws PhpfastcacheLogicException
89
-     */
90
-    public function getModificationDate(): DateTimeInterface;
91
-
92
-    /**
93
-     * @param $date DateTimeInterface
94
-     *
95
-     * @return ExtendedCacheItemInterface
96
-     * @throws PhpfastcacheLogicException
97
-     */
98
-    public function setCreationDate(DateTimeInterface $date): ExtendedCacheItemInterface;
99
-
100
-    /**
101
-     * @param $date DateTimeInterface
102
-     *
103
-     * @return ExtendedCacheItemInterface
104
-     * @throws PhpfastcacheLogicException
105
-     */
106
-    public function setModificationDate(DateTimeInterface $date): ExtendedCacheItemInterface;
107
-
108
-    /**
109
-     * @return int
110
-     */
111
-    public function getTtl(): int;
112
-
113
-    /**
114
-     * @return bool
115
-     */
116
-    public function isExpired(): bool;
117
-
118
-    /**
119
-     * @return bool
120
-     */
121
-    public function isNull(): bool;
122
-
123
-    /**
124
-     * @return bool
125
-     */
126
-    public function isEmpty(): bool;
127
-
128
-    /**
129
-     * Return the data length:
130
-     * - Either the number of char if it's a string (binary mode)
131
-     * - or the number of element if it's an array
132
-     * - or the number returned by count() if it's an object implementing \Countable interface
133
-     * - or -1 for anything else
134
-     *
135
-     * @return int
136
-     */
137
-    public function getLength(): int;
138
-
139
-    /**
140
-     * @param ExtendedCacheItemPoolInterface $driver
141
-     *
142
-     * @return ExtendedCacheItemInterface
143
-     */
144
-    public function setDriver(ExtendedCacheItemPoolInterface $driver): ExtendedCacheItemInterface;
145
-
146
-    /**
147
-     * @param bool $isHit
148
-     *
149
-     * @return ExtendedCacheItemInterface
150
-     */
151
-    public function setHit(bool $isHit): ExtendedCacheItemInterface;
152
-
153
-    /**
154
-     * @param int $step
155
-     *
156
-     * @return ExtendedCacheItemInterface
157
-     * @throws PhpfastcacheInvalidTypeException
158
-     */
159
-    public function increment(int $step = 1): ExtendedCacheItemInterface;
160
-
161
-    /**
162
-     * @param int $step
163
-     *
164
-     * @return ExtendedCacheItemInterface
165
-     * @throws PhpfastcacheInvalidTypeException
166
-     */
167
-    public function decrement(int $step = 1): ExtendedCacheItemInterface;
168
-
169
-    /**
170
-     * @param mixed[]|string $data
171
-     *
172
-     * @return ExtendedCacheItemInterface
173
-     * @throws PhpfastcacheInvalidTypeException
174
-     */
175
-    public function append(array|string $data): ExtendedCacheItemInterface;
176
-
177
-    /**
178
-     * @param mixed[]|string $data
179
-     *
180
-     * @return ExtendedCacheItemInterface
181
-     * @throws PhpfastcacheInvalidTypeException
182
-     */
183
-    public function prepend(array|string $data): ExtendedCacheItemInterface;
184
-
185
-    /**
186
-     * Return the data as a well-formatted string.
187
-     * Any scalar value will be casted to an array
188
-     *
189
-     * @param int $options \json_encode() options
190
-     * @param int $depth \json_encode() depth
191
-     *
192
-     * @return string
193
-     */
194
-    public function getDataAsJsonString(int $options = JSON_THROW_ON_ERROR, int $depth = 512): string;
195
-
196
-    /**
197
-     * @param ExtendedCacheItemPoolInterface $driverPool
198
-     * @return bool
199
-     */
200
-    public function doesItemBelongToThatDriverBackend(ExtendedCacheItemPoolInterface $driverPool): bool;
201
-
202
-    /**
203
-     * @param ExtendedCacheItemInterface $itemTarget
204
-     * @param ExtendedCacheItemPoolInterface|null $itemPoolTarget
205
-     */
206
-    public function cloneInto(ExtendedCacheItemInterface $itemTarget, ?ExtendedCacheItemPoolInterface $itemPoolTarget = null): void;
36
+	/**
37
+	 * Returns the encoded key for the current cache item.
38
+	 * Is a MD5 (default),SHA1,SHA256 hash if "defaultKeyHashFunction" config option is configured
39
+	 * Else return the plain cache item key "defaultKeyHashFunction" config option is emptied
40
+	 *
41
+	 * @return string
42
+	 *   The encoded key string for this cache item.
43
+	 */
44
+	public function getEncodedKey(): string;
45
+
46
+	/**
47
+	 * Returns the cache item value, regardless of hit status.
48
+	 * This method can be called if the cache item is NOT YET
49
+	 * persisted, and you need to access to its set value.
50
+	 *
51
+	 * Although not part of the CacheItemInterface, this method is used by
52
+	 * the pool for extracting information for saving.
53
+	 *
54
+	 * @return mixed
55
+	 *
56
+	 * @internal This method is used internally by phpfastcache, so you should not use it in your application.
57
+	 * @SuppressWarnings(PHPMD.CamelCaseMethodName)
58
+	 */
59
+	public function _getData(): mixed; // @phpcs:ignore
60
+
61
+	/**
62
+	 * @return DateTimeInterface
63
+	 */
64
+	public function getExpirationDate(): DateTimeInterface;
65
+
66
+	/**
67
+	 * Alias of expireAt() with forced $expiration param
68
+	 *
69
+	 * @param DateTimeInterface $expiration
70
+	 *   The point in time after which the item MUST be considered expired.
71
+	 *   If null is passed explicitly, a default value MAY be used. If none is set,
72
+	 *   the value should be stored permanently or for as long as the
73
+	 *   implementation allows.
74
+	 *
75
+	 * @return ExtendedCacheItemInterface
76
+	 *   The called object.
77
+	 */
78
+	public function setExpirationDate(DateTimeInterface $expiration): ExtendedCacheItemInterface;
79
+
80
+	/**
81
+	 * @return DateTimeInterface
82
+	 * @throws PhpfastcacheLogicException
83
+	 */
84
+	public function getCreationDate(): DateTimeInterface;
85
+
86
+	/**
87
+	 * @return DateTimeInterface
88
+	 * @throws PhpfastcacheLogicException
89
+	 */
90
+	public function getModificationDate(): DateTimeInterface;
91
+
92
+	/**
93
+	 * @param $date DateTimeInterface
94
+	 *
95
+	 * @return ExtendedCacheItemInterface
96
+	 * @throws PhpfastcacheLogicException
97
+	 */
98
+	public function setCreationDate(DateTimeInterface $date): ExtendedCacheItemInterface;
99
+
100
+	/**
101
+	 * @param $date DateTimeInterface
102
+	 *
103
+	 * @return ExtendedCacheItemInterface
104
+	 * @throws PhpfastcacheLogicException
105
+	 */
106
+	public function setModificationDate(DateTimeInterface $date): ExtendedCacheItemInterface;
107
+
108
+	/**
109
+	 * @return int
110
+	 */
111
+	public function getTtl(): int;
112
+
113
+	/**
114
+	 * @return bool
115
+	 */
116
+	public function isExpired(): bool;
117
+
118
+	/**
119
+	 * @return bool
120
+	 */
121
+	public function isNull(): bool;
122
+
123
+	/**
124
+	 * @return bool
125
+	 */
126
+	public function isEmpty(): bool;
127
+
128
+	/**
129
+	 * Return the data length:
130
+	 * - Either the number of char if it's a string (binary mode)
131
+	 * - or the number of element if it's an array
132
+	 * - or the number returned by count() if it's an object implementing \Countable interface
133
+	 * - or -1 for anything else
134
+	 *
135
+	 * @return int
136
+	 */
137
+	public function getLength(): int;
138
+
139
+	/**
140
+	 * @param ExtendedCacheItemPoolInterface $driver
141
+	 *
142
+	 * @return ExtendedCacheItemInterface
143
+	 */
144
+	public function setDriver(ExtendedCacheItemPoolInterface $driver): ExtendedCacheItemInterface;
145
+
146
+	/**
147
+	 * @param bool $isHit
148
+	 *
149
+	 * @return ExtendedCacheItemInterface
150
+	 */
151
+	public function setHit(bool $isHit): ExtendedCacheItemInterface;
152
+
153
+	/**
154
+	 * @param int $step
155
+	 *
156
+	 * @return ExtendedCacheItemInterface
157
+	 * @throws PhpfastcacheInvalidTypeException
158
+	 */
159
+	public function increment(int $step = 1): ExtendedCacheItemInterface;
160
+
161
+	/**
162
+	 * @param int $step
163
+	 *
164
+	 * @return ExtendedCacheItemInterface
165
+	 * @throws PhpfastcacheInvalidTypeException
166
+	 */
167
+	public function decrement(int $step = 1): ExtendedCacheItemInterface;
168
+
169
+	/**
170
+	 * @param mixed[]|string $data
171
+	 *
172
+	 * @return ExtendedCacheItemInterface
173
+	 * @throws PhpfastcacheInvalidTypeException
174
+	 */
175
+	public function append(array|string $data): ExtendedCacheItemInterface;
176
+
177
+	/**
178
+	 * @param mixed[]|string $data
179
+	 *
180
+	 * @return ExtendedCacheItemInterface
181
+	 * @throws PhpfastcacheInvalidTypeException
182
+	 */
183
+	public function prepend(array|string $data): ExtendedCacheItemInterface;
184
+
185
+	/**
186
+	 * Return the data as a well-formatted string.
187
+	 * Any scalar value will be casted to an array
188
+	 *
189
+	 * @param int $options \json_encode() options
190
+	 * @param int $depth \json_encode() depth
191
+	 *
192
+	 * @return string
193
+	 */
194
+	public function getDataAsJsonString(int $options = JSON_THROW_ON_ERROR, int $depth = 512): string;
195
+
196
+	/**
197
+	 * @param ExtendedCacheItemPoolInterface $driverPool
198
+	 * @return bool
199
+	 */
200
+	public function doesItemBelongToThatDriverBackend(ExtendedCacheItemPoolInterface $driverPool): bool;
201
+
202
+	/**
203
+	 * @param ExtendedCacheItemInterface $itemTarget
204
+	 * @param ExtendedCacheItemPoolInterface|null $itemPoolTarget
205
+	 */
206
+	public function cloneInto(ExtendedCacheItemInterface $itemTarget, ?ExtendedCacheItemPoolInterface $itemPoolTarget = null): void;
207 207
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      * @return ExtendedCacheItemInterface
173 173
      * @throws PhpfastcacheInvalidTypeException
174 174
      */
175
-    public function append(array|string $data): ExtendedCacheItemInterface;
175
+    public function append(array | string $data): ExtendedCacheItemInterface;
176 176
 
177 177
     /**
178 178
      * @param mixed[]|string $data
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      * @return ExtendedCacheItemInterface
181 181
      * @throws PhpfastcacheInvalidTypeException
182 182
      */
183
-    public function prepend(array|string $data): ExtendedCacheItemInterface;
183
+    public function prepend(array | string $data): ExtendedCacheItemInterface;
184 184
 
185 185
     /**
186 186
      * Return the data as a well-formatted string.
Please login to merge, or discard this patch.
phpfastcache/phpfastcache/lib/Phpfastcache/Core/Item/CacheItemTrait.php 3 patches
Indentation   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -27,123 +27,123 @@
 block discarded – undo
27 27
 
28 28
 trait CacheItemTrait
29 29
 {
30
-    use EventManagerDispatcherTrait;
31
-    use ClassNamespaceResolverTrait;
32
-
33
-    protected string $key;
34
-
35
-    protected mixed $data;
36
-
37
-    protected DateTimeInterface $expirationDate;
38
-
39
-    protected DateTimeInterface $creationDate;
40
-
41
-    protected DateTimeInterface $modificationDate;
42
-
43
-    protected bool $isHit = false;
44
-
45
-    public function getKey(): string
46
-    {
47
-        return $this->key;
48
-    }
49
-
50
-    public function get(): mixed
51
-    {
52
-        if (!$this->isHit()) {
53
-            return null;
54
-        }
55
-
56
-        return $this->data;
57
-    }
58
-
59
-    /**
60
-     * @throws PhpfastcacheInvalidArgumentException
61
-     */
62
-    public function set(mixed $value): static
63
-    {
64
-        if ($value instanceof \Closure) {
65
-            throw new PhpfastcacheInvalidArgumentException('The value set cannot be an instance of \\Closure.');
66
-        }
67
-
68
-        if (\is_resource($value)) {
69
-            throw new PhpfastcacheInvalidArgumentException('The value set cannot be a resource');
70
-        }
71
-
72
-        $this->eventManager->dispatch(Event::CACHE_ITEM_SET, $this, new EventReferenceParameter($value, true));
73
-
74
-        $this->data = $value;
75
-
76
-        return $this;
77
-    }
78
-
79
-    /**
80
-     * @return bool
81
-     */
82
-    public function isHit(): bool
83
-    {
84
-        return $this->isHit;
85
-    }
86
-
87
-    /**
88
-     * @param bool $isHit
89
-     * @return ExtendedCacheItemInterface
90
-     */
91
-    public function setHit(bool $isHit): ExtendedCacheItemInterface
92
-    {
93
-        $this->isHit = $isHit;
94
-
95
-        return $this;
96
-    }
97
-
98
-    /**
99
-     * @throws PhpfastcacheInvalidArgumentException
100
-     */
101
-    public function expiresAt(?\DateTimeInterface $expiration): static
102
-    {
103
-        if ($expiration instanceof DateTimeInterface) {
104
-            $this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AT, $this, $expiration);
105
-            $this->expirationDate = $this->demutateDatetime($expiration);
106
-        } else {
107
-            throw new PhpfastcacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration));
108
-        }
109
-
110
-        return $this;
111
-    }
112
-
113
-    /**
114
-     * @return $this
115
-     * @throws PhpfastcacheInvalidArgumentException
116
-     * @throws \Exception
117
-     */
118
-    public function expiresAfter(int|\DateInterval|null $time): static
119
-    {
120
-        if (\is_numeric($time)) {
121
-            if ($time <= 0) {
122
-                /**
123
-                 * 5 months, however memcached or memory cached will be gone when u restart it
124
-                 * just recommended for sqlite. files
125
-                 */
126
-                $time = 30 * 24 * 3600 * 5;
127
-            }
128
-
129
-            $this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AFTER, $this, $time);
130
-
131
-            $this->expirationDate = (new DateTime())->add(new DateInterval(\sprintf('PT%dS', $time)));
132
-        } elseif ($time instanceof DateInterval) {
133
-            $this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AFTER, $this, $time);
134
-
135
-            $this->expirationDate = (new DateTime())->add($time);
136
-        } else {
137
-            throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid date format, got "%s"', \gettype($time)));
138
-        }
139
-
140
-        return $this;
141
-    }
142
-
143
-    protected function demutateDatetime(\DateTimeInterface $dateTime): \DateTimeInterface
144
-    {
145
-        return $dateTime instanceof \DateTimeImmutable
146
-            ? \DateTime::createFromImmutable($dateTime)
147
-            : $dateTime;
148
-    }
30
+	use EventManagerDispatcherTrait;
31
+	use ClassNamespaceResolverTrait;
32
+
33
+	protected string $key;
34
+
35
+	protected mixed $data;
36
+
37
+	protected DateTimeInterface $expirationDate;
38
+
39
+	protected DateTimeInterface $creationDate;
40
+
41
+	protected DateTimeInterface $modificationDate;
42
+
43
+	protected bool $isHit = false;
44
+
45
+	public function getKey(): string
46
+	{
47
+		return $this->key;
48
+	}
49
+
50
+	public function get(): mixed
51
+	{
52
+		if (!$this->isHit()) {
53
+			return null;
54
+		}
55
+
56
+		return $this->data;
57
+	}
58
+
59
+	/**
60
+	 * @throws PhpfastcacheInvalidArgumentException
61
+	 */
62
+	public function set(mixed $value): static
63
+	{
64
+		if ($value instanceof \Closure) {
65
+			throw new PhpfastcacheInvalidArgumentException('The value set cannot be an instance of \\Closure.');
66
+		}
67
+
68
+		if (\is_resource($value)) {
69
+			throw new PhpfastcacheInvalidArgumentException('The value set cannot be a resource');
70
+		}
71
+
72
+		$this->eventManager->dispatch(Event::CACHE_ITEM_SET, $this, new EventReferenceParameter($value, true));
73
+
74
+		$this->data = $value;
75
+
76
+		return $this;
77
+	}
78
+
79
+	/**
80
+	 * @return bool
81
+	 */
82
+	public function isHit(): bool
83
+	{
84
+		return $this->isHit;
85
+	}
86
+
87
+	/**
88
+	 * @param bool $isHit
89
+	 * @return ExtendedCacheItemInterface
90
+	 */
91
+	public function setHit(bool $isHit): ExtendedCacheItemInterface
92
+	{
93
+		$this->isHit = $isHit;
94
+
95
+		return $this;
96
+	}
97
+
98
+	/**
99
+	 * @throws PhpfastcacheInvalidArgumentException
100
+	 */
101
+	public function expiresAt(?\DateTimeInterface $expiration): static
102
+	{
103
+		if ($expiration instanceof DateTimeInterface) {
104
+			$this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AT, $this, $expiration);
105
+			$this->expirationDate = $this->demutateDatetime($expiration);
106
+		} else {
107
+			throw new PhpfastcacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration));
108
+		}
109
+
110
+		return $this;
111
+	}
112
+
113
+	/**
114
+	 * @return $this
115
+	 * @throws PhpfastcacheInvalidArgumentException
116
+	 * @throws \Exception
117
+	 */
118
+	public function expiresAfter(int|\DateInterval|null $time): static
119
+	{
120
+		if (\is_numeric($time)) {
121
+			if ($time <= 0) {
122
+				/**
123
+				 * 5 months, however memcached or memory cached will be gone when u restart it
124
+				 * just recommended for sqlite. files
125
+				 */
126
+				$time = 30 * 24 * 3600 * 5;
127
+			}
128
+
129
+			$this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AFTER, $this, $time);
130
+
131
+			$this->expirationDate = (new DateTime())->add(new DateInterval(\sprintf('PT%dS', $time)));
132
+		} elseif ($time instanceof DateInterval) {
133
+			$this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AFTER, $this, $time);
134
+
135
+			$this->expirationDate = (new DateTime())->add($time);
136
+		} else {
137
+			throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid date format, got "%s"', \gettype($time)));
138
+		}
139
+
140
+		return $this;
141
+	}
142
+
143
+	protected function demutateDatetime(\DateTimeInterface $dateTime): \DateTimeInterface
144
+	{
145
+		return $dateTime instanceof \DateTimeImmutable
146
+			? \DateTime::createFromImmutable($dateTime)
147
+			: $dateTime;
148
+	}
149 149
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@
 block discarded – undo
115 115
      * @throws PhpfastcacheInvalidArgumentException
116 116
      * @throws \Exception
117 117
      */
118
-    public function expiresAfter(int|\DateInterval|null $time): static
118
+    public function expiresAfter(int | \DateInterval | null $time): static
119 119
     {
120 120
         if (\is_numeric($time)) {
121 121
             if ($time <= 0) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -103,7 +103,8 @@  discard block
 block discarded – undo
103 103
         if ($expiration instanceof DateTimeInterface) {
104 104
             $this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AT, $this, $expiration);
105 105
             $this->expirationDate = $this->demutateDatetime($expiration);
106
-        } else {
106
+        }
107
+        else {
107 108
             throw new PhpfastcacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration));
108 109
         }
109 110
 
@@ -129,11 +130,13 @@  discard block
 block discarded – undo
129 130
             $this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AFTER, $this, $time);
130 131
 
131 132
             $this->expirationDate = (new DateTime())->add(new DateInterval(\sprintf('PT%dS', $time)));
132
-        } elseif ($time instanceof DateInterval) {
133
+        }
134
+        elseif ($time instanceof DateInterval) {
133 135
             $this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AFTER, $this, $time);
134 136
 
135 137
             $this->expirationDate = (new DateTime())->add($time);
136
-        } else {
138
+        }
139
+        else {
137 140
             throw new PhpfastcacheInvalidArgumentException(\sprintf('Invalid date format, got "%s"', \gettype($time)));
138 141
         }
139 142
 
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -27,109 +27,109 @@
 block discarded – undo
27 27
 
28 28
 trait ExtendedCacheItemPoolTrait
29 29
 {
30
-    use CacheItemPoolTrait;
31
-    use AggregatablePoolTrait;
32
-
33
-    /**
34
-     * @inheritDoc
35
-     * @param string $pattern
36
-     * @return array<string, mixed>
37
-     */
38
-    public function getAllItems(string $pattern = ''): iterable
39
-    {
40
-        $driverReadAllKeysCallback = fn (string $pattern): iterable => $this->driverReadAllKeys($pattern);
41
-
42
-        /**
43
-         * This event allow you to customize the callback and wrap it to an invoker
44
-         * like SebastianBergmann\Invoke\Invoke, so you can set up custom timeouts.
45
-         */
46
-        $this->eventManager->dispatch(Event::CACHE_GET_ALL_ITEMS, $this, new EventReferenceParameter($driverReadAllKeysCallback));
47
-        $keys = $driverReadAllKeysCallback($pattern);
48
-
49
-        if (count($keys) > 0) {
50
-            return $this->getItems($keys instanceof \Traversable ? iterator_to_array($keys) : $keys);
51
-        }
52
-
53
-        return [];
54
-    }
55
-
56
-    /**
57
-     * @inheritDoc
58
-     * @throws PhpfastcacheCoreException
59
-     * @throws PhpfastcacheDriverException
60
-     * @throws PhpfastcacheInvalidArgumentException
61
-     * @throws PhpfastcacheLogicException
62
-     */
63
-    public function getItemsAsJsonString(array $keys = [], int $options = \JSON_THROW_ON_ERROR, int $depth = 512): string
64
-    {
65
-        return \json_encode(
66
-            \array_map(
67
-                static fn(CacheItemInterface $item) => $item->get(),
68
-                \array_values($this->getItems($keys))
69
-            ),
70
-            $options,
71
-            $depth
72
-        );
73
-    }
74
-
75
-    public function detachAllItems(): static
76
-    {
77
-        foreach ($this->itemInstances as $item) {
78
-            $this->detachItem($item);
79
-        }
80
-
81
-        return $this;
82
-    }
83
-
84
-    public function detachItem(CacheItemInterface $item): static
85
-    {
86
-        if (isset($this->itemInstances[$item->getKey()])) {
87
-            $this->deregisterItem($item->getKey());
88
-        }
89
-
90
-        return $this;
91
-    }
92
-
93
-    /**
94
-     * @param ExtendedCacheItemInterface ...$items
95
-     * @return bool
96
-     * @throws PhpfastcacheCoreException
97
-     * @throws PhpfastcacheDriverException
98
-     * @throws PhpfastcacheInvalidArgumentException
99
-     * @throws PhpfastcacheLogicException
100
-     */
101
-    public function saveMultiple(ExtendedCacheItemInterface ...$items): bool
102
-    {
103
-        $this->eventManager->dispatch(Event::CACHE_SAVE_MULTIPLE_ITEMS, $this, new EventReferenceParameter($items));
104
-
105
-        if (\count($items)) {
106
-            foreach ($items as $item) {
107
-                $this->save($item);
108
-            }
109
-            return true;
110
-        }
111
-        return false;
112
-    }
113
-
114
-    /**
115
-     * @return string
116
-     */
117
-    public function getHelp(): string
118
-    {
119
-        return '';
120
-    }
121
-
122
-    /**
123
-     * @throws PhpfastcacheInvalidArgumentException
124
-     */
125
-    public function throwUnsupportedDriverReadAllPattern(string $linkReference = ''): void
126
-    {
127
-        throw new PhpfastcacheInvalidArgumentException(
128
-            sprintf(
129
-                '%s does not support a pattern argument.%s',
130
-                $this->getDriverName(),
131
-                $linkReference ? " See $linkReference" : ''
132
-            )
133
-        );
134
-    }
30
+	use CacheItemPoolTrait;
31
+	use AggregatablePoolTrait;
32
+
33
+	/**
34
+	 * @inheritDoc
35
+	 * @param string $pattern
36
+	 * @return array<string, mixed>
37
+	 */
38
+	public function getAllItems(string $pattern = ''): iterable
39
+	{
40
+		$driverReadAllKeysCallback = fn (string $pattern): iterable => $this->driverReadAllKeys($pattern);
41
+
42
+		/**
43
+		 * This event allow you to customize the callback and wrap it to an invoker
44
+		 * like SebastianBergmann\Invoke\Invoke, so you can set up custom timeouts.
45
+		 */
46
+		$this->eventManager->dispatch(Event::CACHE_GET_ALL_ITEMS, $this, new EventReferenceParameter($driverReadAllKeysCallback));
47
+		$keys = $driverReadAllKeysCallback($pattern);
48
+
49
+		if (count($keys) > 0) {
50
+			return $this->getItems($keys instanceof \Traversable ? iterator_to_array($keys) : $keys);
51
+		}
52
+
53
+		return [];
54
+	}
55
+
56
+	/**
57
+	 * @inheritDoc
58
+	 * @throws PhpfastcacheCoreException
59
+	 * @throws PhpfastcacheDriverException
60
+	 * @throws PhpfastcacheInvalidArgumentException
61
+	 * @throws PhpfastcacheLogicException
62
+	 */
63
+	public function getItemsAsJsonString(array $keys = [], int $options = \JSON_THROW_ON_ERROR, int $depth = 512): string
64
+	{
65
+		return \json_encode(
66
+			\array_map(
67
+				static fn(CacheItemInterface $item) => $item->get(),
68
+				\array_values($this->getItems($keys))
69
+			),
70
+			$options,
71
+			$depth
72
+		);
73
+	}
74
+
75
+	public function detachAllItems(): static
76
+	{
77
+		foreach ($this->itemInstances as $item) {
78
+			$this->detachItem($item);
79
+		}
80
+
81
+		return $this;
82
+	}
83
+
84
+	public function detachItem(CacheItemInterface $item): static
85
+	{
86
+		if (isset($this->itemInstances[$item->getKey()])) {
87
+			$this->deregisterItem($item->getKey());
88
+		}
89
+
90
+		return $this;
91
+	}
92
+
93
+	/**
94
+	 * @param ExtendedCacheItemInterface ...$items
95
+	 * @return bool
96
+	 * @throws PhpfastcacheCoreException
97
+	 * @throws PhpfastcacheDriverException
98
+	 * @throws PhpfastcacheInvalidArgumentException
99
+	 * @throws PhpfastcacheLogicException
100
+	 */
101
+	public function saveMultiple(ExtendedCacheItemInterface ...$items): bool
102
+	{
103
+		$this->eventManager->dispatch(Event::CACHE_SAVE_MULTIPLE_ITEMS, $this, new EventReferenceParameter($items));
104
+
105
+		if (\count($items)) {
106
+			foreach ($items as $item) {
107
+				$this->save($item);
108
+			}
109
+			return true;
110
+		}
111
+		return false;
112
+	}
113
+
114
+	/**
115
+	 * @return string
116
+	 */
117
+	public function getHelp(): string
118
+	{
119
+		return '';
120
+	}
121
+
122
+	/**
123
+	 * @throws PhpfastcacheInvalidArgumentException
124
+	 */
125
+	public function throwUnsupportedDriverReadAllPattern(string $linkReference = ''): void
126
+	{
127
+		throw new PhpfastcacheInvalidArgumentException(
128
+			sprintf(
129
+				'%s does not support a pattern argument.%s',
130
+				$this->getDriverName(),
131
+				$linkReference ? " See $linkReference" : ''
132
+			)
133
+		);
134
+	}
135 135
 }
Please login to merge, or discard this patch.
phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php 3 patches
Indentation   +584 added lines, -584 removed lines patch added patch discarded remove patch
@@ -41,590 +41,590 @@
 block discarded – undo
41 41
  */
42 42
 trait CacheItemPoolTrait
43 43
 {
44
-    use DriverBaseTrait {
45
-        DriverBaseTrait::__construct as __driverBaseConstruct;
46
-    }
47
-
48
-    /**
49
-     * @var string
50
-     */
51
-    protected static string $unsupportedKeyChars = '{}()/\@:';
52
-
53
-    /**
54
-     * @var ExtendedCacheItemInterface[]|CacheItemInterface[]
55
-     */
56
-    protected array $deferredList = [];
57
-
58
-    /**
59
-     * @var ExtendedCacheItemInterface[]|CacheItemInterface[]
60
-     */
61
-    protected array $itemInstances = [];
62
-
63
-    protected DriverIO $IO;
64
-
65
-    public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface $config, string $instanceId, EventManagerInterface $em)
66
-    {
67
-        $this->IO = new DriverIO();
68
-        $this->__driverBaseConstruct($config, $instanceId, $em);
69
-    }
70
-
71
-    /**
72
-     * @throws PhpfastcacheLogicException
73
-     * @throws PhpfastcacheInvalidArgumentException
74
-     */
75
-    public function setItem(CacheItemInterface $item): static
76
-    {
77
-        if (self::getItemClass() === $item::class) {
78
-            if (!$this->getConfig()->isUseStaticItemCaching()) {
79
-                throw new PhpfastcacheLogicException(
80
-                    'The static item caching option (useStaticItemCaching) is disabled so you cannot attach an item.'
81
-                );
82
-            }
83
-
84
-            $this->itemInstances[$item->getKey()] = $item;
85
-
86
-            return $this;
87
-        }
88
-        throw new PhpfastcacheInvalidArgumentException(
89
-            \sprintf(
90
-                'Invalid cache item class "%s" for driver "%s".',
91
-                get_class($item),
92
-                get_class($this)
93
-            )
94
-        );
95
-    }
96
-
97
-    /**
98
-     * @inheritDoc
99
-     * @throws PhpfastcacheCoreException
100
-     * @throws PhpfastcacheDriverException
101
-     * @throws PhpfastcacheInvalidArgumentException
102
-     * @throws PhpfastcacheLogicException
103
-     */
104
-    public function getItems(array $keys = []): iterable
105
-    {
106
-        $items = [];
107
-
108
-        /**
109
-         * Usually, drivers that are able to enable cache slams
110
-         * does not benefit of driverReadMultiple() call.
111
-         */
112
-        if (!$this->getConfig()->isPreventCacheSlams()) {
113
-            $this->validateCacheKeys(...$keys);
114
-
115
-            /**
116
-             * Check for local item instances first.
117
-             */
118
-            foreach ($keys as $index => $key) {
119
-                if (isset($this->itemInstances[$key]) && $this->getConfig()->isUseStaticItemCaching()) {
120
-                    $items[$key] = $this->itemInstances[$key];
121
-                    // Key already exists in local item instances, no need to fetch it again.
122
-                    unset($keys[$index]);
123
-                }
124
-            }
125
-            $keys = array_values($keys);
126
-
127
-            /**
128
-             * If there's still keys to fetch, let's choose the right method (if supported).
129
-             */
130
-            if (count($keys) > 1) {
131
-                $items = array_merge(
132
-                    array_combine($keys, array_map(fn($key) => new (self::getItemClass())($this, $key, $this->eventManager), $keys)),
133
-                    $items
134
-                );
135
-
136
-                try {
137
-                    $driverArrays = $this->driverReadMultiple(...$items);
138
-                } catch (PhpfastcacheUnsupportedMethodException) {
139
-                    /**
140
-                     * Fallback for drivers that does not yet implement driverReadMultiple() method.
141
-                     */
142
-                    $driverArrays = array_combine(
143
-                        array_map(fn($item) => $item->getKey(), $items),
144
-                        array_map(fn($item) => $this->driverRead($item), $items)
145
-                    );
146
-                } finally {
147
-                    foreach ($items as $item) {
148
-                        $driverArray = $driverArrays[$item->getKey()] ?? null;
149
-                        if ($driverArray !== null) {
150
-                            $item->set($this->driverUnwrapData($driverArray));
151
-                            $item->expiresAt($this->driverUnwrapEdate($driverArray));
152
-                            if ($this->getConfig()->isItemDetailedDate()) {
153
-                                /**
154
-                                 * If the itemDetailedDate has been
155
-                                 * set after caching, we MUST inject
156
-                                 * a new DateTime object on the fly
157
-                                 */
158
-                                $item->setCreationDate($this->driverUnwrapCdate($driverArray) ?: new DateTime());
159
-                                $item->setModificationDate($this->driverUnwrapMdate($driverArray) ?: new DateTime());
160
-                            }
161
-                            $item->setTags($this->driverUnwrapTags($driverArray));
162
-                            $this->handleExpiredCacheItem($item);
163
-                        } else {
164
-                            $item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
165
-                        }
166
-                        $item->isHit() ? $this->getIO()->incReadHit() : $this->getIO()->incReadMiss();
167
-                    }
168
-                }
169
-            } else {
170
-                $index = array_key_first($keys);
171
-                if ($index !== null) {
172
-                    $items[$keys[$index]] = $this->getItem($keys[$index]);
173
-                }
174
-            }
175
-        } else {
176
-            $collection = [];
177
-
178
-            foreach ($keys as $key) {
179
-                $collection[$key] = $this->getItem($key);
180
-            }
181
-
182
-            return $collection;
183
-        }
184
-
185
-        $this->eventManager->dispatch(Event::CACHE_GET_ITEMS, $this, $items);
186
-
187
-        return $items;
188
-    }
189
-
190
-    /**
191
-     * @param string $key
192
-     * @return ExtendedCacheItemInterface
193
-     * @throws PhpfastcacheCoreException
194
-     * @throws PhpfastcacheInvalidArgumentException
195
-     * @throws PhpfastcacheLogicException
196
-     * @throws PhpfastcacheDriverException
197
-     *
198
-     * @SuppressWarnings(PHPMD.NPathComplexity)
199
-     * @SuppressWarnings(PHPMD.GotoStatement)
200
-     */
201
-    public function getItem(string $key): ExtendedCacheItemInterface
202
-    {
203
-        /**
204
-         * Replace array_key_exists by isset
205
-         * due to performance issue on huge
206
-         * loop dispatching operations
207
-         */
208
-        if (!isset($this->itemInstances[$key]) || !$this->getConfig()->isUseStaticItemCaching()) {
209
-            $this->validateCacheKeys($key);
210
-
211
-            /** @var $item ExtendedCacheItemInterface */
212
-            $item = new (self::getItemClass())($this, $key, $this->eventManager);
213
-
214
-            $getItemDriverRead = function (float $cacheSlamsSpendSeconds = 0) use (&$getItemDriverRead, $item): void {
215
-                $config = $this->getConfig();
216
-
217
-                $driverArray = $this->driverRead($item);
218
-
219
-                if ($driverArray) {
220
-                    $driverData = $this->driverUnwrapData($driverArray);
221
-
222
-                    if ($config instanceof IOConfigurationOptionInterface && $config->isPreventCacheSlams()) {
223
-                        while ($driverData instanceof ItemBatch) {
224
-                            if ($driverData->getItemDate()->getTimestamp() + $config->getCacheSlamsTimeout() < \time()) {
225
-                                /**
226
-                                 * The timeout has been reached
227
-                                 * Consider that the batch has
228
-                                 * failed and serve an empty item
229
-                                 * to avoid get stuck with a
230
-                                 * batch item stored in driver
231
-                                 */
232
-                                $this->handleExpiredCacheItem($item);
233
-                                return;
234
-                            }
235
-
236
-                            $this->eventManager->dispatch(Event::CACHE_GET_ITEM_IN_SLAM_BATCH, $this, $driverData, $cacheSlamsSpendSeconds);
237
-
238
-                            /**
239
-                             * Wait for a second before
240
-                             * attempting to get exit
241
-                             * the current batch process
242
-                             */
243
-                            \usleep(100000);
244
-
245
-                            $getItemDriverRead($cacheSlamsSpendSeconds + 0.1);
246
-                        }
247
-                    }
248
-
249
-                    $item->set($driverData);
250
-                    $item->expiresAt($this->driverUnwrapEdate($driverArray));
251
-
252
-                    if ($this->getConfig()->isItemDetailedDate()) {
253
-                        /**
254
-                         * If the itemDetailedDate has been
255
-                         * set after caching, we MUST inject
256
-                         * a new DateTime object on the fly
257
-                         */
258
-                        $item->setCreationDate($this->driverUnwrapCdate($driverArray) ?: new DateTime());
259
-                        $item->setModificationDate($this->driverUnwrapMdate($driverArray) ?: new DateTime());
260
-                    }
261
-
262
-                    $item->setTags($this->driverUnwrapTags($driverArray));
263
-                    $this->handleExpiredCacheItem($item);
264
-                } else {
265
-                    $item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
266
-                }
267
-            };
268
-            $getItemDriverRead();
269
-        } else {
270
-            $item = $this->itemInstances[$key];
271
-        }
272
-
273
-        $this->eventManager->dispatch(Event::CACHE_GET_ITEM, $this, $item);
274
-
275
-        $item->isHit() ? $this->getIO()->incReadHit() : $this->getIO()->incReadMiss();
276
-
277
-        return $item;
278
-    }
279
-
280
-    /**
281
-     * @param string $key
282
-     * @return bool
283
-     * @throws PhpfastcacheCoreException
284
-     * @throws PhpfastcacheDriverException
285
-     * @throws PhpfastcacheInvalidArgumentException
286
-     * @throws PhpfastcacheLogicException
287
-     */
288
-    public function hasItem(string $key): bool
289
-    {
290
-        return $this->getItem($key)->isHit();
291
-    }
292
-
293
-    /**
294
-     * @return bool
295
-     * @throws PhpfastcacheCoreException
296
-     * @throws PhpfastcacheDriverException
297
-     * @throws PhpfastcacheLogicException
298
-     * @throws PhpfastcacheIOException
299
-     */
300
-    public function clear(): bool
301
-    {
302
-        $this->eventManager->dispatch(Event::CACHE_CLEAR_ITEM, $this, $this->itemInstances);
303
-
304
-        $this->getIO()->incWriteHit();
305
-        // Faster than detachAllItems()
306
-        $this->itemInstances = [];
307
-
308
-        return $this->driverClear();
309
-    }
310
-
311
-    /**
312
-     * @inheritDoc
313
-     * @throws PhpfastcacheCoreException
314
-     * @throws PhpfastcacheDriverException
315
-     * @throws PhpfastcacheInvalidArgumentException
316
-     * @throws PhpfastcacheLogicException
317
-     */
318
-    public function deleteItems(array $keys): bool
319
-    {
320
-        if (count($keys) > 1) {
321
-            $return = true;
322
-            try {
323
-                $items = $this->getItems($keys);
324
-                $return = $this->driverDeleteMultiple($keys);
325
-                foreach ($items as $item) {
326
-                    $item->setHit(false);
327
-
328
-                    if (!\str_starts_with($item->getKey(), TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX)) {
329
-                        $this->cleanItemTags($item);
330
-                    }
331
-                }
332
-                $this->getIO()->incWriteHit();
333
-                $this->eventManager->dispatch(Event::CACHE_DELETE_ITEMS, $this, $items);
334
-                $this->deregisterItems($keys);
335
-            } catch (PhpfastcacheUnsupportedMethodException) {
336
-                foreach ($keys as $key) {
337
-                    $result = $this->deleteItem($key);
338
-                    if ($result !== true) {
339
-                        $return = false;
340
-                    }
341
-                }
342
-            }
343
-
344
-            return $return;
345
-        }
346
-
347
-        $index = array_key_first($keys);
348
-        if ($index !== null) {
349
-            return $this->deleteItem($keys[$index]);
350
-        }
351
-
352
-        return false;
353
-    }
354
-
355
-    /**
356
-     * @param string $key
357
-     * @return bool
358
-     * @throws PhpfastcacheCoreException
359
-     * @throws PhpfastcacheDriverException
360
-     * @throws PhpfastcacheInvalidArgumentException
361
-     * @throws PhpfastcacheLogicException
362
-     */
363
-    public function deleteItem(string $key): bool
364
-    {
365
-        $item = $this->getItem($key);
366
-        if ($item->isHit()) {
367
-            $result = $this->driverDelete($item->getKey(), $item->getEncodedKey());
368
-            $item->setHit(false);
369
-            $this->getIO()->incWriteHit();
370
-
371
-            $this->eventManager->dispatch(Event::CACHE_DELETE_ITEM, $this, $item);
372
-
373
-            /**
374
-             * De-register the item instance
375
-             * then collect gc cycles
376
-             */
377
-            $this->deregisterItem($key);
378
-
379
-            /**
380
-             * Perform a tag cleanup to avoid memory leaks
381
-             */
382
-            if (!\str_starts_with($key, TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX)) {
383
-                $this->cleanItemTags($item);
384
-            }
385
-
386
-            return $result;
387
-        }
388
-
389
-        return false;
390
-    }
391
-
392
-    /**
393
-     * @param CacheItemInterface $item
394
-     * @return bool
395
-     */
396
-    public function saveDeferred(CacheItemInterface $item): bool
397
-    {
398
-        $this->assertCacheItemType($item, self::getItemClass());
399
-        if (!\array_key_exists($item->getKey(), $this->itemInstances)) {
400
-            $this->itemInstances[$item->getKey()] = $item;
401
-        } elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
402
-            throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
403
-        }
404
-
405
-        $this->eventManager->dispatch(Event::CACHE_SAVE_DEFERRED_ITEM, $this, $item);
406
-        $this->deferredList[$item->getKey()] = $item;
407
-
408
-        return true;
409
-    }
410
-
411
-    /**
412
-     * @return bool
413
-     * @throws PhpfastcacheCoreException
414
-     * @throws PhpfastcacheDriverException
415
-     * @throws PhpfastcacheInvalidArgumentException
416
-     * @throws PhpfastcacheLogicException
417
-     */
418
-    public function commit(): bool
419
-    {
420
-        $this->eventManager->dispatch(Event::CACHE_COMMIT_ITEM, $this, new EventReferenceParameter($this->deferredList));
421
-
422
-        if (\count($this->deferredList)) {
423
-            $return = true;
424
-            foreach ($this->deferredList as $key => $item) {
425
-                $result = $this->save($item);
426
-                unset($this->deferredList[$key]);
427
-                if ($result !== true) {
428
-                    $return = $result;
429
-                }
430
-            }
431
-
432
-            return $return;
433
-        }
434
-        return false;
435
-    }
436
-
437
-    /**
438
-     * @param CacheItemInterface $item
439
-     * @return bool
440
-     * @throws PhpfastcacheCoreException
441
-     * @throws PhpfastcacheDriverException
442
-     * @throws PhpfastcacheIOException
443
-     * @throws PhpfastcacheInvalidArgumentException
444
-     * @throws PhpfastcacheLogicException
445
-     */
446
-    public function save(CacheItemInterface $item): bool
447
-    {
448
-        $this->assertCacheItemType($item, self::getItemClass());
449
-        /**
450
-         * @var ExtendedCacheItemInterface $item
451
-         *
452
-         * Replace array_key_exists by isset
453
-         * due to performance issue on huge
454
-         * loop dispatching operations
455
-         */
456
-        if (!isset($this->itemInstances[$item->getKey()])) {
457
-            if ($this->getConfig()->isUseStaticItemCaching()) {
458
-                $this->itemInstances[$item->getKey()] = $item;
459
-            }
460
-        } elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
461
-            throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
462
-        }
463
-
464
-        $this->assertCacheItemType($item, self::getItemClass());
465
-        $this->eventManager->dispatch(Event::CACHE_SAVE_ITEM, $this, $item);
466
-
467
-        if ($this->getConfig() instanceof IOConfigurationOptionInterface && $this->getConfig()->isPreventCacheSlams()) {
468
-            /**
469
-             * @var $itemBatch ExtendedCacheItemInterface
470
-             */
471
-            $itemClassName = self::getItemClass();
472
-            $itemBatch = new $itemClassName($this, $item->getKey(), $this->eventManager);
473
-            $itemBatch->set(new ItemBatch($item->getKey(), new DateTime()))
474
-                ->expiresAfter($this->getConfig()->getCacheSlamsTimeout());
475
-
476
-            /**
477
-             * To avoid SPL mismatches
478
-             * we have to re-attach the
479
-             * original item to the pool
480
-             */
481
-            $this->driverWrite($itemBatch);
482
-            $this->detachItem($itemBatch);
483
-            $this->attachItem($item);
484
-        }
485
-
486
-
487
-        if ($this->driverWrite($item) && $this->driverWriteTags($item)) {
488
-            $item->setHit(true)
489
-                ->clearRemovedTags();
490
-
491
-            if ($this->getConfig()->isItemDetailedDate()) {
492
-                $item->setModificationDate(new \DateTime());
493
-            }
494
-
495
-            $this->getIO()->incWriteHit();
496
-
497
-            return true;
498
-        }
499
-
500
-        return false;
501
-    }
502
-
503
-    /**
504
-     * @return DriverIO
505
-     */
506
-    public function getIO(): DriverIO
507
-    {
508
-        return $this->IO;
509
-    }
510
-
511
-    /**
512
-     * @internal This method de-register an item from $this->itemInstances
513
-     */
514
-    protected function deregisterItem(string $itemKey): static
515
-    {
516
-        unset($this->itemInstances[$itemKey]);
517
-
518
-        if (\gc_enabled()) {
519
-            \gc_collect_cycles();
520
-        }
521
-
522
-        return $this;
523
-    }
524
-
525
-    /**
526
-     * @param string[] $itemKeys
527
-     * @internal This method de-register multiple items from $this->itemInstances
528
-     */
529
-    protected function deregisterItems(array $itemKeys): static
530
-    {
531
-        $this->itemInstances = array_diff_key($this->itemInstances, array_flip($itemKeys));
532
-
533
-        if (\gc_enabled()) {
534
-            \gc_collect_cycles();
535
-        }
536
-
537
-        return $this;
538
-    }
539
-
540
-    /**
541
-     * @throws PhpfastcacheLogicException
542
-     */
543
-    public function attachItem(CacheItemInterface $item): static
544
-    {
545
-        if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
546
-            throw new PhpfastcacheLogicException(
547
-                'The item already exists and cannot be overwritten because the Spl object hash mismatches ! 
44
+	use DriverBaseTrait {
45
+		DriverBaseTrait::__construct as __driverBaseConstruct;
46
+	}
47
+
48
+	/**
49
+	 * @var string
50
+	 */
51
+	protected static string $unsupportedKeyChars = '{}()/\@:';
52
+
53
+	/**
54
+	 * @var ExtendedCacheItemInterface[]|CacheItemInterface[]
55
+	 */
56
+	protected array $deferredList = [];
57
+
58
+	/**
59
+	 * @var ExtendedCacheItemInterface[]|CacheItemInterface[]
60
+	 */
61
+	protected array $itemInstances = [];
62
+
63
+	protected DriverIO $IO;
64
+
65
+	public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface $config, string $instanceId, EventManagerInterface $em)
66
+	{
67
+		$this->IO = new DriverIO();
68
+		$this->__driverBaseConstruct($config, $instanceId, $em);
69
+	}
70
+
71
+	/**
72
+	 * @throws PhpfastcacheLogicException
73
+	 * @throws PhpfastcacheInvalidArgumentException
74
+	 */
75
+	public function setItem(CacheItemInterface $item): static
76
+	{
77
+		if (self::getItemClass() === $item::class) {
78
+			if (!$this->getConfig()->isUseStaticItemCaching()) {
79
+				throw new PhpfastcacheLogicException(
80
+					'The static item caching option (useStaticItemCaching) is disabled so you cannot attach an item.'
81
+				);
82
+			}
83
+
84
+			$this->itemInstances[$item->getKey()] = $item;
85
+
86
+			return $this;
87
+		}
88
+		throw new PhpfastcacheInvalidArgumentException(
89
+			\sprintf(
90
+				'Invalid cache item class "%s" for driver "%s".',
91
+				get_class($item),
92
+				get_class($this)
93
+			)
94
+		);
95
+	}
96
+
97
+	/**
98
+	 * @inheritDoc
99
+	 * @throws PhpfastcacheCoreException
100
+	 * @throws PhpfastcacheDriverException
101
+	 * @throws PhpfastcacheInvalidArgumentException
102
+	 * @throws PhpfastcacheLogicException
103
+	 */
104
+	public function getItems(array $keys = []): iterable
105
+	{
106
+		$items = [];
107
+
108
+		/**
109
+		 * Usually, drivers that are able to enable cache slams
110
+		 * does not benefit of driverReadMultiple() call.
111
+		 */
112
+		if (!$this->getConfig()->isPreventCacheSlams()) {
113
+			$this->validateCacheKeys(...$keys);
114
+
115
+			/**
116
+			 * Check for local item instances first.
117
+			 */
118
+			foreach ($keys as $index => $key) {
119
+				if (isset($this->itemInstances[$key]) && $this->getConfig()->isUseStaticItemCaching()) {
120
+					$items[$key] = $this->itemInstances[$key];
121
+					// Key already exists in local item instances, no need to fetch it again.
122
+					unset($keys[$index]);
123
+				}
124
+			}
125
+			$keys = array_values($keys);
126
+
127
+			/**
128
+			 * If there's still keys to fetch, let's choose the right method (if supported).
129
+			 */
130
+			if (count($keys) > 1) {
131
+				$items = array_merge(
132
+					array_combine($keys, array_map(fn($key) => new (self::getItemClass())($this, $key, $this->eventManager), $keys)),
133
+					$items
134
+				);
135
+
136
+				try {
137
+					$driverArrays = $this->driverReadMultiple(...$items);
138
+				} catch (PhpfastcacheUnsupportedMethodException) {
139
+					/**
140
+					 * Fallback for drivers that does not yet implement driverReadMultiple() method.
141
+					 */
142
+					$driverArrays = array_combine(
143
+						array_map(fn($item) => $item->getKey(), $items),
144
+						array_map(fn($item) => $this->driverRead($item), $items)
145
+					);
146
+				} finally {
147
+					foreach ($items as $item) {
148
+						$driverArray = $driverArrays[$item->getKey()] ?? null;
149
+						if ($driverArray !== null) {
150
+							$item->set($this->driverUnwrapData($driverArray));
151
+							$item->expiresAt($this->driverUnwrapEdate($driverArray));
152
+							if ($this->getConfig()->isItemDetailedDate()) {
153
+								/**
154
+								 * If the itemDetailedDate has been
155
+								 * set after caching, we MUST inject
156
+								 * a new DateTime object on the fly
157
+								 */
158
+								$item->setCreationDate($this->driverUnwrapCdate($driverArray) ?: new DateTime());
159
+								$item->setModificationDate($this->driverUnwrapMdate($driverArray) ?: new DateTime());
160
+							}
161
+							$item->setTags($this->driverUnwrapTags($driverArray));
162
+							$this->handleExpiredCacheItem($item);
163
+						} else {
164
+							$item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
165
+						}
166
+						$item->isHit() ? $this->getIO()->incReadHit() : $this->getIO()->incReadMiss();
167
+					}
168
+				}
169
+			} else {
170
+				$index = array_key_first($keys);
171
+				if ($index !== null) {
172
+					$items[$keys[$index]] = $this->getItem($keys[$index]);
173
+				}
174
+			}
175
+		} else {
176
+			$collection = [];
177
+
178
+			foreach ($keys as $key) {
179
+				$collection[$key] = $this->getItem($key);
180
+			}
181
+
182
+			return $collection;
183
+		}
184
+
185
+		$this->eventManager->dispatch(Event::CACHE_GET_ITEMS, $this, $items);
186
+
187
+		return $items;
188
+	}
189
+
190
+	/**
191
+	 * @param string $key
192
+	 * @return ExtendedCacheItemInterface
193
+	 * @throws PhpfastcacheCoreException
194
+	 * @throws PhpfastcacheInvalidArgumentException
195
+	 * @throws PhpfastcacheLogicException
196
+	 * @throws PhpfastcacheDriverException
197
+	 *
198
+	 * @SuppressWarnings(PHPMD.NPathComplexity)
199
+	 * @SuppressWarnings(PHPMD.GotoStatement)
200
+	 */
201
+	public function getItem(string $key): ExtendedCacheItemInterface
202
+	{
203
+		/**
204
+		 * Replace array_key_exists by isset
205
+		 * due to performance issue on huge
206
+		 * loop dispatching operations
207
+		 */
208
+		if (!isset($this->itemInstances[$key]) || !$this->getConfig()->isUseStaticItemCaching()) {
209
+			$this->validateCacheKeys($key);
210
+
211
+			/** @var $item ExtendedCacheItemInterface */
212
+			$item = new (self::getItemClass())($this, $key, $this->eventManager);
213
+
214
+			$getItemDriverRead = function (float $cacheSlamsSpendSeconds = 0) use (&$getItemDriverRead, $item): void {
215
+				$config = $this->getConfig();
216
+
217
+				$driverArray = $this->driverRead($item);
218
+
219
+				if ($driverArray) {
220
+					$driverData = $this->driverUnwrapData($driverArray);
221
+
222
+					if ($config instanceof IOConfigurationOptionInterface && $config->isPreventCacheSlams()) {
223
+						while ($driverData instanceof ItemBatch) {
224
+							if ($driverData->getItemDate()->getTimestamp() + $config->getCacheSlamsTimeout() < \time()) {
225
+								/**
226
+								 * The timeout has been reached
227
+								 * Consider that the batch has
228
+								 * failed and serve an empty item
229
+								 * to avoid get stuck with a
230
+								 * batch item stored in driver
231
+								 */
232
+								$this->handleExpiredCacheItem($item);
233
+								return;
234
+							}
235
+
236
+							$this->eventManager->dispatch(Event::CACHE_GET_ITEM_IN_SLAM_BATCH, $this, $driverData, $cacheSlamsSpendSeconds);
237
+
238
+							/**
239
+							 * Wait for a second before
240
+							 * attempting to get exit
241
+							 * the current batch process
242
+							 */
243
+							\usleep(100000);
244
+
245
+							$getItemDriverRead($cacheSlamsSpendSeconds + 0.1);
246
+						}
247
+					}
248
+
249
+					$item->set($driverData);
250
+					$item->expiresAt($this->driverUnwrapEdate($driverArray));
251
+
252
+					if ($this->getConfig()->isItemDetailedDate()) {
253
+						/**
254
+						 * If the itemDetailedDate has been
255
+						 * set after caching, we MUST inject
256
+						 * a new DateTime object on the fly
257
+						 */
258
+						$item->setCreationDate($this->driverUnwrapCdate($driverArray) ?: new DateTime());
259
+						$item->setModificationDate($this->driverUnwrapMdate($driverArray) ?: new DateTime());
260
+					}
261
+
262
+					$item->setTags($this->driverUnwrapTags($driverArray));
263
+					$this->handleExpiredCacheItem($item);
264
+				} else {
265
+					$item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
266
+				}
267
+			};
268
+			$getItemDriverRead();
269
+		} else {
270
+			$item = $this->itemInstances[$key];
271
+		}
272
+
273
+		$this->eventManager->dispatch(Event::CACHE_GET_ITEM, $this, $item);
274
+
275
+		$item->isHit() ? $this->getIO()->incReadHit() : $this->getIO()->incReadMiss();
276
+
277
+		return $item;
278
+	}
279
+
280
+	/**
281
+	 * @param string $key
282
+	 * @return bool
283
+	 * @throws PhpfastcacheCoreException
284
+	 * @throws PhpfastcacheDriverException
285
+	 * @throws PhpfastcacheInvalidArgumentException
286
+	 * @throws PhpfastcacheLogicException
287
+	 */
288
+	public function hasItem(string $key): bool
289
+	{
290
+		return $this->getItem($key)->isHit();
291
+	}
292
+
293
+	/**
294
+	 * @return bool
295
+	 * @throws PhpfastcacheCoreException
296
+	 * @throws PhpfastcacheDriverException
297
+	 * @throws PhpfastcacheLogicException
298
+	 * @throws PhpfastcacheIOException
299
+	 */
300
+	public function clear(): bool
301
+	{
302
+		$this->eventManager->dispatch(Event::CACHE_CLEAR_ITEM, $this, $this->itemInstances);
303
+
304
+		$this->getIO()->incWriteHit();
305
+		// Faster than detachAllItems()
306
+		$this->itemInstances = [];
307
+
308
+		return $this->driverClear();
309
+	}
310
+
311
+	/**
312
+	 * @inheritDoc
313
+	 * @throws PhpfastcacheCoreException
314
+	 * @throws PhpfastcacheDriverException
315
+	 * @throws PhpfastcacheInvalidArgumentException
316
+	 * @throws PhpfastcacheLogicException
317
+	 */
318
+	public function deleteItems(array $keys): bool
319
+	{
320
+		if (count($keys) > 1) {
321
+			$return = true;
322
+			try {
323
+				$items = $this->getItems($keys);
324
+				$return = $this->driverDeleteMultiple($keys);
325
+				foreach ($items as $item) {
326
+					$item->setHit(false);
327
+
328
+					if (!\str_starts_with($item->getKey(), TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX)) {
329
+						$this->cleanItemTags($item);
330
+					}
331
+				}
332
+				$this->getIO()->incWriteHit();
333
+				$this->eventManager->dispatch(Event::CACHE_DELETE_ITEMS, $this, $items);
334
+				$this->deregisterItems($keys);
335
+			} catch (PhpfastcacheUnsupportedMethodException) {
336
+				foreach ($keys as $key) {
337
+					$result = $this->deleteItem($key);
338
+					if ($result !== true) {
339
+						$return = false;
340
+					}
341
+				}
342
+			}
343
+
344
+			return $return;
345
+		}
346
+
347
+		$index = array_key_first($keys);
348
+		if ($index !== null) {
349
+			return $this->deleteItem($keys[$index]);
350
+		}
351
+
352
+		return false;
353
+	}
354
+
355
+	/**
356
+	 * @param string $key
357
+	 * @return bool
358
+	 * @throws PhpfastcacheCoreException
359
+	 * @throws PhpfastcacheDriverException
360
+	 * @throws PhpfastcacheInvalidArgumentException
361
+	 * @throws PhpfastcacheLogicException
362
+	 */
363
+	public function deleteItem(string $key): bool
364
+	{
365
+		$item = $this->getItem($key);
366
+		if ($item->isHit()) {
367
+			$result = $this->driverDelete($item->getKey(), $item->getEncodedKey());
368
+			$item->setHit(false);
369
+			$this->getIO()->incWriteHit();
370
+
371
+			$this->eventManager->dispatch(Event::CACHE_DELETE_ITEM, $this, $item);
372
+
373
+			/**
374
+			 * De-register the item instance
375
+			 * then collect gc cycles
376
+			 */
377
+			$this->deregisterItem($key);
378
+
379
+			/**
380
+			 * Perform a tag cleanup to avoid memory leaks
381
+			 */
382
+			if (!\str_starts_with($key, TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX)) {
383
+				$this->cleanItemTags($item);
384
+			}
385
+
386
+			return $result;
387
+		}
388
+
389
+		return false;
390
+	}
391
+
392
+	/**
393
+	 * @param CacheItemInterface $item
394
+	 * @return bool
395
+	 */
396
+	public function saveDeferred(CacheItemInterface $item): bool
397
+	{
398
+		$this->assertCacheItemType($item, self::getItemClass());
399
+		if (!\array_key_exists($item->getKey(), $this->itemInstances)) {
400
+			$this->itemInstances[$item->getKey()] = $item;
401
+		} elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
402
+			throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
403
+		}
404
+
405
+		$this->eventManager->dispatch(Event::CACHE_SAVE_DEFERRED_ITEM, $this, $item);
406
+		$this->deferredList[$item->getKey()] = $item;
407
+
408
+		return true;
409
+	}
410
+
411
+	/**
412
+	 * @return bool
413
+	 * @throws PhpfastcacheCoreException
414
+	 * @throws PhpfastcacheDriverException
415
+	 * @throws PhpfastcacheInvalidArgumentException
416
+	 * @throws PhpfastcacheLogicException
417
+	 */
418
+	public function commit(): bool
419
+	{
420
+		$this->eventManager->dispatch(Event::CACHE_COMMIT_ITEM, $this, new EventReferenceParameter($this->deferredList));
421
+
422
+		if (\count($this->deferredList)) {
423
+			$return = true;
424
+			foreach ($this->deferredList as $key => $item) {
425
+				$result = $this->save($item);
426
+				unset($this->deferredList[$key]);
427
+				if ($result !== true) {
428
+					$return = $result;
429
+				}
430
+			}
431
+
432
+			return $return;
433
+		}
434
+		return false;
435
+	}
436
+
437
+	/**
438
+	 * @param CacheItemInterface $item
439
+	 * @return bool
440
+	 * @throws PhpfastcacheCoreException
441
+	 * @throws PhpfastcacheDriverException
442
+	 * @throws PhpfastcacheIOException
443
+	 * @throws PhpfastcacheInvalidArgumentException
444
+	 * @throws PhpfastcacheLogicException
445
+	 */
446
+	public function save(CacheItemInterface $item): bool
447
+	{
448
+		$this->assertCacheItemType($item, self::getItemClass());
449
+		/**
450
+		 * @var ExtendedCacheItemInterface $item
451
+		 *
452
+		 * Replace array_key_exists by isset
453
+		 * due to performance issue on huge
454
+		 * loop dispatching operations
455
+		 */
456
+		if (!isset($this->itemInstances[$item->getKey()])) {
457
+			if ($this->getConfig()->isUseStaticItemCaching()) {
458
+				$this->itemInstances[$item->getKey()] = $item;
459
+			}
460
+		} elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
461
+			throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
462
+		}
463
+
464
+		$this->assertCacheItemType($item, self::getItemClass());
465
+		$this->eventManager->dispatch(Event::CACHE_SAVE_ITEM, $this, $item);
466
+
467
+		if ($this->getConfig() instanceof IOConfigurationOptionInterface && $this->getConfig()->isPreventCacheSlams()) {
468
+			/**
469
+			 * @var $itemBatch ExtendedCacheItemInterface
470
+			 */
471
+			$itemClassName = self::getItemClass();
472
+			$itemBatch = new $itemClassName($this, $item->getKey(), $this->eventManager);
473
+			$itemBatch->set(new ItemBatch($item->getKey(), new DateTime()))
474
+				->expiresAfter($this->getConfig()->getCacheSlamsTimeout());
475
+
476
+			/**
477
+			 * To avoid SPL mismatches
478
+			 * we have to re-attach the
479
+			 * original item to the pool
480
+			 */
481
+			$this->driverWrite($itemBatch);
482
+			$this->detachItem($itemBatch);
483
+			$this->attachItem($item);
484
+		}
485
+
486
+
487
+		if ($this->driverWrite($item) && $this->driverWriteTags($item)) {
488
+			$item->setHit(true)
489
+				->clearRemovedTags();
490
+
491
+			if ($this->getConfig()->isItemDetailedDate()) {
492
+				$item->setModificationDate(new \DateTime());
493
+			}
494
+
495
+			$this->getIO()->incWriteHit();
496
+
497
+			return true;
498
+		}
499
+
500
+		return false;
501
+	}
502
+
503
+	/**
504
+	 * @return DriverIO
505
+	 */
506
+	public function getIO(): DriverIO
507
+	{
508
+		return $this->IO;
509
+	}
510
+
511
+	/**
512
+	 * @internal This method de-register an item from $this->itemInstances
513
+	 */
514
+	protected function deregisterItem(string $itemKey): static
515
+	{
516
+		unset($this->itemInstances[$itemKey]);
517
+
518
+		if (\gc_enabled()) {
519
+			\gc_collect_cycles();
520
+		}
521
+
522
+		return $this;
523
+	}
524
+
525
+	/**
526
+	 * @param string[] $itemKeys
527
+	 * @internal This method de-register multiple items from $this->itemInstances
528
+	 */
529
+	protected function deregisterItems(array $itemKeys): static
530
+	{
531
+		$this->itemInstances = array_diff_key($this->itemInstances, array_flip($itemKeys));
532
+
533
+		if (\gc_enabled()) {
534
+			\gc_collect_cycles();
535
+		}
536
+
537
+		return $this;
538
+	}
539
+
540
+	/**
541
+	 * @throws PhpfastcacheLogicException
542
+	 */
543
+	public function attachItem(CacheItemInterface $item): static
544
+	{
545
+		if (isset($this->itemInstances[$item->getKey()]) && \spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
546
+			throw new PhpfastcacheLogicException(
547
+				'The item already exists and cannot be overwritten because the Spl object hash mismatches ! 
548 548
                 You probably tried to re-attach a detached item which has been already retrieved from cache.'
549
-            );
550
-        }
551
-
552
-        if (!$this->getConfig()->isUseStaticItemCaching()) {
553
-            throw new PhpfastcacheLogicException(
554
-                'The static item caching option (useStaticItemCaching) is disabled so you cannot attach an item.'
555
-            );
556
-        }
557
-
558
-        $this->itemInstances[$item->getKey()] = $item;
559
-
560
-        return $this;
561
-    }
562
-
563
-    public function isAttached(CacheItemInterface $item): bool
564
-    {
565
-        if (isset($this->itemInstances[$item->getKey()])) {
566
-            return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]);
567
-        }
568
-        return false;
569
-    }
570
-
571
-    protected function validateCacheKeys(string ...$keys): void
572
-    {
573
-        foreach ($keys as $key) {
574
-            if (\preg_match('~([' . \preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)) {
575
-                throw new PhpfastcacheInvalidArgumentException(
576
-                    'Unsupported key character detected: "' . $matches[1] . '". 
549
+			);
550
+		}
551
+
552
+		if (!$this->getConfig()->isUseStaticItemCaching()) {
553
+			throw new PhpfastcacheLogicException(
554
+				'The static item caching option (useStaticItemCaching) is disabled so you cannot attach an item.'
555
+			);
556
+		}
557
+
558
+		$this->itemInstances[$item->getKey()] = $item;
559
+
560
+		return $this;
561
+	}
562
+
563
+	public function isAttached(CacheItemInterface $item): bool
564
+	{
565
+		if (isset($this->itemInstances[$item->getKey()])) {
566
+			return \spl_object_hash($item) === \spl_object_hash($this->itemInstances[$item->getKey()]);
567
+		}
568
+		return false;
569
+	}
570
+
571
+	protected function validateCacheKeys(string ...$keys): void
572
+	{
573
+		foreach ($keys as $key) {
574
+			if (\preg_match('~([' . \preg_quote(self::$unsupportedKeyChars, '~') . ']+)~', $key, $matches)) {
575
+				throw new PhpfastcacheInvalidArgumentException(
576
+					'Unsupported key character detected: "' . $matches[1] . '". 
577 577
                     Please check: https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV6%5D-Unsupported-characters-in-key-identifiers'
578
-                );
579
-            }
580
-        }
581
-    }
582
-
583
-    protected function handleExpiredCacheItem(ExtendedCacheItemInterface $item): void
584
-    {
585
-        if ($item->isExpired()) {
586
-            /**
587
-             * Using driverDelete() instead of delete()
588
-             * to avoid infinite loop caused by
589
-             * getItem() call in delete() method
590
-             * As we MUST return an item in any
591
-             * way, we do not de-register here
592
-             */
593
-            $this->driverDelete($item->getKey(), $item->getEncodedKey());
594
-
595
-            /**
596
-             * Reset the Item
597
-             */
598
-            $item->set(null)
599
-                ->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()))
600
-                ->setHit(false)
601
-                ->setTags([]);
602
-
603
-            if ($this->getConfig()->isItemDetailedDate()) {
604
-                /**
605
-                 * If the itemDetailedDate has been
606
-                 * set after caching, we MUST inject
607
-                 * a new DateTime object on the fly
608
-                 */
609
-                $item->setCreationDate(new DateTime());
610
-                $item->setModificationDate(new DateTime());
611
-            }
612
-        } else {
613
-            $item->setHit(true);
614
-        }
615
-    }
616
-
617
-    /**
618
-     * @param ExtendedCacheItemInterface[] $items
619
-     * @param bool $encoded
620
-     * @param string $keyPrefix
621
-     * @return string[]
622
-     */
623
-    protected function getKeys(array $items, bool $encoded = false, string $keyPrefix = ''): array
624
-    {
625
-        return array_map(
626
-            static fn(ExtendedCacheItemInterface $item) => $keyPrefix . ($encoded ? $item->getEncodedKey() : $item->getKey()),
627
-            $items
628
-        );
629
-    }
578
+				);
579
+			}
580
+		}
581
+	}
582
+
583
+	protected function handleExpiredCacheItem(ExtendedCacheItemInterface $item): void
584
+	{
585
+		if ($item->isExpired()) {
586
+			/**
587
+			 * Using driverDelete() instead of delete()
588
+			 * to avoid infinite loop caused by
589
+			 * getItem() call in delete() method
590
+			 * As we MUST return an item in any
591
+			 * way, we do not de-register here
592
+			 */
593
+			$this->driverDelete($item->getKey(), $item->getEncodedKey());
594
+
595
+			/**
596
+			 * Reset the Item
597
+			 */
598
+			$item->set(null)
599
+				->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()))
600
+				->setHit(false)
601
+				->setTags([]);
602
+
603
+			if ($this->getConfig()->isItemDetailedDate()) {
604
+				/**
605
+				 * If the itemDetailedDate has been
606
+				 * set after caching, we MUST inject
607
+				 * a new DateTime object on the fly
608
+				 */
609
+				$item->setCreationDate(new DateTime());
610
+				$item->setModificationDate(new DateTime());
611
+			}
612
+		} else {
613
+			$item->setHit(true);
614
+		}
615
+	}
616
+
617
+	/**
618
+	 * @param ExtendedCacheItemInterface[] $items
619
+	 * @param bool $encoded
620
+	 * @param string $keyPrefix
621
+	 * @return string[]
622
+	 */
623
+	protected function getKeys(array $items, bool $encoded = false, string $keyPrefix = ''): array
624
+	{
625
+		return array_map(
626
+			static fn(ExtendedCacheItemInterface $item) => $keyPrefix . ($encoded ? $item->getEncodedKey() : $item->getKey()),
627
+			$items
628
+		);
629
+	}
630 630
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@
 block discarded – undo
211 211
             /** @var $item ExtendedCacheItemInterface */
212 212
             $item = new (self::getItemClass())($this, $key, $this->eventManager);
213 213
 
214
-            $getItemDriverRead = function (float $cacheSlamsSpendSeconds = 0) use (&$getItemDriverRead, $item): void {
214
+            $getItemDriverRead = function(float $cacheSlamsSpendSeconds = 0) use (&$getItemDriverRead, $item): void {
215 215
                 $config = $this->getConfig();
216 216
 
217 217
                 $driverArray = $this->driverRead($item);
Please login to merge, or discard this patch.
Braces   +23 added lines, -13 removed lines patch added patch discarded remove patch
@@ -62,8 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
     protected DriverIO $IO;
64 64
 
65
-    public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface $config, string $instanceId, EventManagerInterface $em)
66
-    {
65
+    public function __construct(#[\SensitiveParameter] ConfigurationOptionInterface $config, string $instanceId, EventManagerInterface $em) {
67 66
         $this->IO = new DriverIO();
68 67
         $this->__driverBaseConstruct($config, $instanceId, $em);
69 68
     }
@@ -135,7 +134,8 @@  discard block
 block discarded – undo
135 134
 
136 135
                 try {
137 136
                     $driverArrays = $this->driverReadMultiple(...$items);
138
-                } catch (PhpfastcacheUnsupportedMethodException) {
137
+                }
138
+                catch (PhpfastcacheUnsupportedMethodException) {
139 139
                     /**
140 140
                      * Fallback for drivers that does not yet implement driverReadMultiple() method.
141 141
                      */
@@ -143,7 +143,8 @@  discard block
 block discarded – undo
143 143
                         array_map(fn($item) => $item->getKey(), $items),
144 144
                         array_map(fn($item) => $this->driverRead($item), $items)
145 145
                     );
146
-                } finally {
146
+                }
147
+                finally {
147 148
                     foreach ($items as $item) {
148 149
                         $driverArray = $driverArrays[$item->getKey()] ?? null;
149 150
                         if ($driverArray !== null) {
@@ -160,19 +161,22 @@  discard block
 block discarded – undo
160 161
                             }
161 162
                             $item->setTags($this->driverUnwrapTags($driverArray));
162 163
                             $this->handleExpiredCacheItem($item);
163
-                        } else {
164
+                        }
165
+                        else {
164 166
                             $item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
165 167
                         }
166 168
                         $item->isHit() ? $this->getIO()->incReadHit() : $this->getIO()->incReadMiss();
167 169
                     }
168 170
                 }
169
-            } else {
171
+            }
172
+            else {
170 173
                 $index = array_key_first($keys);
171 174
                 if ($index !== null) {
172 175
                     $items[$keys[$index]] = $this->getItem($keys[$index]);
173 176
                 }
174 177
             }
175
-        } else {
178
+        }
179
+        else {
176 180
             $collection = [];
177 181
 
178 182
             foreach ($keys as $key) {
@@ -261,12 +265,14 @@  discard block
 block discarded – undo
261 265
 
262 266
                     $item->setTags($this->driverUnwrapTags($driverArray));
263 267
                     $this->handleExpiredCacheItem($item);
264
-                } else {
268
+                }
269
+                else {
265 270
                     $item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
266 271
                 }
267 272
             };
268 273
             $getItemDriverRead();
269
-        } else {
274
+        }
275
+        else {
270 276
             $item = $this->itemInstances[$key];
271 277
         }
272 278
 
@@ -332,7 +338,8 @@  discard block
 block discarded – undo
332 338
                 $this->getIO()->incWriteHit();
333 339
                 $this->eventManager->dispatch(Event::CACHE_DELETE_ITEMS, $this, $items);
334 340
                 $this->deregisterItems($keys);
335
-            } catch (PhpfastcacheUnsupportedMethodException) {
341
+            }
342
+            catch (PhpfastcacheUnsupportedMethodException) {
336 343
                 foreach ($keys as $key) {
337 344
                     $result = $this->deleteItem($key);
338 345
                     if ($result !== true) {
@@ -398,7 +405,8 @@  discard block
 block discarded – undo
398 405
         $this->assertCacheItemType($item, self::getItemClass());
399 406
         if (!\array_key_exists($item->getKey(), $this->itemInstances)) {
400 407
             $this->itemInstances[$item->getKey()] = $item;
401
-        } elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
408
+        }
409
+        elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
402 410
             throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
403 411
         }
404 412
 
@@ -457,7 +465,8 @@  discard block
 block discarded – undo
457 465
             if ($this->getConfig()->isUseStaticItemCaching()) {
458 466
                 $this->itemInstances[$item->getKey()] = $item;
459 467
             }
460
-        } elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
468
+        }
469
+        elseif (\spl_object_hash($item) !== \spl_object_hash($this->itemInstances[$item->getKey()])) {
461 470
             throw new RuntimeException('Spl object hash mismatches ! You probably tried to save a detached item which has been already retrieved from cache.');
462 471
         }
463 472
 
@@ -609,7 +618,8 @@  discard block
 block discarded – undo
609 618
                 $item->setCreationDate(new DateTime());
610 619
                 $item->setModificationDate(new DateTime());
611 620
             }
612
-        } else {
621
+        }
622
+        else {
613 623
             $item->setHit(true);
614 624
         }
615 625
     }
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolInterface.php 2 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -21,268 +21,268 @@
 block discarded – undo
21 21
 
22 22
 interface TaggableCacheItemPoolInterface
23 23
 {
24
-    public const DRIVER_TAGS_KEY_PREFIX = '_TAG_';
24
+	public const DRIVER_TAGS_KEY_PREFIX = '_TAG_';
25 25
 
26
-    public const DRIVER_TAGS_WRAPPER_INDEX = 'g';
26
+	public const DRIVER_TAGS_WRAPPER_INDEX = 'g';
27 27
 
28
-    /**
29
-     * Allows you to get cache item(s) by at least **ONE** of the specified matching tag(s).
30
-     * Default behavior
31
-     */
32
-    public const TAG_STRATEGY_ONE = 1;
28
+	/**
29
+	 * Allows you to get cache item(s) by at least **ONE** of the specified matching tag(s).
30
+	 * Default behavior
31
+	 */
32
+	public const TAG_STRATEGY_ONE = 1;
33 33
 
34
-    /**
35
-     * Allows you to get cache item(s) by **ALL** of the specified matching tag(s)
36
-     * The cache item *CAN* have additional tag(s)
37
-     */
38
-    public const TAG_STRATEGY_ALL = 2;
34
+	/**
35
+	 * Allows you to get cache item(s) by **ALL** of the specified matching tag(s)
36
+	 * The cache item *CAN* have additional tag(s)
37
+	 */
38
+	public const TAG_STRATEGY_ALL = 2;
39 39
 
40
-    /**
41
-     * Allows you to get cache item(s) by **ONLY** the specified matching tag(s)
42
-     * The cache item *CANNOT* have additional tag(s)
43
-     */
44
-    public const TAG_STRATEGY_ONLY = 4;
40
+	/**
41
+	 * Allows you to get cache item(s) by **ONLY** the specified matching tag(s)
42
+	 * The cache item *CANNOT* have additional tag(s)
43
+	 */
44
+	public const TAG_STRATEGY_ONLY = 4;
45 45
 
46
-    /**
47
-     * Returns a traversable set of cache items by a tag name.
48
-     *
49
-     * @param string $tagName
50
-     * An indexed array of keys of items to retrieve.
51
-     *
52
-     * @param int $strategy
53
-     *
54
-     * @return ExtendedCacheItemInterface[]
55
-     *   A traversable collection of Cache Items keyed by the cache keys of
56
-     *   each item. A Cache item will be returned for each key, even if that
57
-     *   key is not found. However, if no keys are specified then an empty
58
-     *   traversable MUST be returned instead.
59
-     * @throws InvalidArgumentException
60
-     *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
61
-     *   MUST be thrown.
62
-     *
63
-     */
64
-    public function getItemsByTag(string $tagName, int $strategy = self::TAG_STRATEGY_ONE): array;
46
+	/**
47
+	 * Returns a traversable set of cache items by a tag name.
48
+	 *
49
+	 * @param string $tagName
50
+	 * An indexed array of keys of items to retrieve.
51
+	 *
52
+	 * @param int $strategy
53
+	 *
54
+	 * @return ExtendedCacheItemInterface[]
55
+	 *   A traversable collection of Cache Items keyed by the cache keys of
56
+	 *   each item. A Cache item will be returned for each key, even if that
57
+	 *   key is not found. However, if no keys are specified then an empty
58
+	 *   traversable MUST be returned instead.
59
+	 * @throws InvalidArgumentException
60
+	 *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
61
+	 *   MUST be thrown.
62
+	 *
63
+	 */
64
+	public function getItemsByTag(string $tagName, int $strategy = self::TAG_STRATEGY_ONE): array;
65 65
 
66
-    /**
67
-     * Returns a traversable set of cache items by one of multiple tag names.
68
-     *
69
-     * @param string[] $tagNames
70
-     * An indexed array of keys of items to retrieve.
71
-     *
72
-     * @param int $strategy
73
-     *
74
-     * @return ExtendedCacheItemInterface[]
75
-     *   A traversable collection of Cache Items keyed by the cache keys of
76
-     *   each item. A Cache item will be returned for each key, even if that
77
-     *   key is not found. However, if no keys are specified then an empty
78
-     *   traversable MUST be returned instead.
79
-     * @throws InvalidArgumentException
80
-     *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
81
-     *   MUST be thrown.
82
-     *
83
-     */
84
-    public function getItemsByTags(array $tagNames, int $strategy = self::TAG_STRATEGY_ONE): array;
66
+	/**
67
+	 * Returns a traversable set of cache items by one of multiple tag names.
68
+	 *
69
+	 * @param string[] $tagNames
70
+	 * An indexed array of keys of items to retrieve.
71
+	 *
72
+	 * @param int $strategy
73
+	 *
74
+	 * @return ExtendedCacheItemInterface[]
75
+	 *   A traversable collection of Cache Items keyed by the cache keys of
76
+	 *   each item. A Cache item will be returned for each key, even if that
77
+	 *   key is not found. However, if no keys are specified then an empty
78
+	 *   traversable MUST be returned instead.
79
+	 * @throws InvalidArgumentException
80
+	 *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
81
+	 *   MUST be thrown.
82
+	 *
83
+	 */
84
+	public function getItemsByTags(array $tagNames, int $strategy = self::TAG_STRATEGY_ONE): array;
85 85
 
86
-    /**
87
-     * Returns A json string that represents an array of items by tags-based.
88
-     *
89
-     * @param string[] $tagNames
90
-     * An indexed array of keys of items to retrieve.
91
-     * @param int $option \json_encode() options
92
-     * @param int $depth \json_encode() depth
93
-     * @param int $strategy
94
-     *
95
-     * @return string
96
-     * @throws InvalidArgumentException
97
-     *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
98
-     *   MUST be thrown.
99
-     *
100
-     */
101
-    public function getItemsByTagsAsJsonString(array $tagNames, int $option = \JSON_THROW_ON_ERROR, int $depth = 512, int $strategy = self::TAG_STRATEGY_ONE): string;
86
+	/**
87
+	 * Returns A json string that represents an array of items by tags-based.
88
+	 *
89
+	 * @param string[] $tagNames
90
+	 * An indexed array of keys of items to retrieve.
91
+	 * @param int $option \json_encode() options
92
+	 * @param int $depth \json_encode() depth
93
+	 * @param int $strategy
94
+	 *
95
+	 * @return string
96
+	 * @throws InvalidArgumentException
97
+	 *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
98
+	 *   MUST be thrown.
99
+	 *
100
+	 */
101
+	public function getItemsByTagsAsJsonString(array $tagNames, int $option = \JSON_THROW_ON_ERROR, int $depth = 512, int $strategy = self::TAG_STRATEGY_ONE): string;
102 102
 
103
-    /**
104
-     * Removes the item from the pool by tag.
105
-     *
106
-     * @param string $tagName
107
-     *   The tag for which to delete
108
-     *
109
-     * @param int $strategy
110
-     *
111
-     * @return bool
112
-     *   True if the item was successfully removed. False if there was an error.
113
-     * @throws InvalidArgumentException
114
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
115
-     *   MUST be thrown.
116
-     *
117
-     */
118
-    public function deleteItemsByTag(string $tagName, int $strategy = self::TAG_STRATEGY_ONE): bool;
103
+	/**
104
+	 * Removes the item from the pool by tag.
105
+	 *
106
+	 * @param string $tagName
107
+	 *   The tag for which to delete
108
+	 *
109
+	 * @param int $strategy
110
+	 *
111
+	 * @return bool
112
+	 *   True if the item was successfully removed. False if there was an error.
113
+	 * @throws InvalidArgumentException
114
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
115
+	 *   MUST be thrown.
116
+	 *
117
+	 */
118
+	public function deleteItemsByTag(string $tagName, int $strategy = self::TAG_STRATEGY_ONE): bool;
119 119
 
120
-    /**
121
-     * Removes the item from the pool by one of multiple tag names.
122
-     *
123
-     * @param string[] $tagNames
124
-     *   The tag for which to delete
125
-     *
126
-     * @param int $strategy
127
-     *
128
-     * @return bool
129
-     *   True if the items were successfully removed. False if there was an error.
130
-     * @throws InvalidArgumentException
131
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
132
-     *   MUST be thrown.
133
-     *
134
-     */
135
-    public function deleteItemsByTags(array $tagNames, int $strategy = self::TAG_STRATEGY_ONE): bool;
120
+	/**
121
+	 * Removes the item from the pool by one of multiple tag names.
122
+	 *
123
+	 * @param string[] $tagNames
124
+	 *   The tag for which to delete
125
+	 *
126
+	 * @param int $strategy
127
+	 *
128
+	 * @return bool
129
+	 *   True if the items were successfully removed. False if there was an error.
130
+	 * @throws InvalidArgumentException
131
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
132
+	 *   MUST be thrown.
133
+	 *
134
+	 */
135
+	public function deleteItemsByTags(array $tagNames, int $strategy = self::TAG_STRATEGY_ONE): bool;
136 136
 
137
-    /**
138
-     * Increment the items from the pool by tag.
139
-     *
140
-     * @param string $tagName
141
-     *   The tag for which to increment
142
-     *
143
-     * @param int $step
144
-     *
145
-     * @param int $strategy
146
-     *
147
-     * @return bool
148
-     *   True if the item was successfully incremented. False if there was an error.
149
-     * @throws InvalidArgumentException
150
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
151
-     *   MUST be thrown.
152
-     *
153
-     */
154
-    public function incrementItemsByTag(string $tagName, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
137
+	/**
138
+	 * Increment the items from the pool by tag.
139
+	 *
140
+	 * @param string $tagName
141
+	 *   The tag for which to increment
142
+	 *
143
+	 * @param int $step
144
+	 *
145
+	 * @param int $strategy
146
+	 *
147
+	 * @return bool
148
+	 *   True if the item was successfully incremented. False if there was an error.
149
+	 * @throws InvalidArgumentException
150
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
151
+	 *   MUST be thrown.
152
+	 *
153
+	 */
154
+	public function incrementItemsByTag(string $tagName, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
155 155
 
156
-    /**
157
-     * Increment the items from the pool by one of multiple tag names.
158
-     *
159
-     * @param string[] $tagNames
160
-     *   The tag for which to increment
161
-     *
162
-     * @param int $step
163
-     *
164
-     * @param int $strategy
165
-     *
166
-     * @return bool
167
-     *   True if the items were successfully incremented. False if there was an error.
168
-     * @throws InvalidArgumentException
169
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
170
-     *   MUST be thrown.
171
-     *
172
-     */
173
-    public function incrementItemsByTags(array $tagNames, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
156
+	/**
157
+	 * Increment the items from the pool by one of multiple tag names.
158
+	 *
159
+	 * @param string[] $tagNames
160
+	 *   The tag for which to increment
161
+	 *
162
+	 * @param int $step
163
+	 *
164
+	 * @param int $strategy
165
+	 *
166
+	 * @return bool
167
+	 *   True if the items were successfully incremented. False if there was an error.
168
+	 * @throws InvalidArgumentException
169
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
170
+	 *   MUST be thrown.
171
+	 *
172
+	 */
173
+	public function incrementItemsByTags(array $tagNames, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
174 174
 
175
-    /**
176
-     * Decrement the items from the pool by tag.
177
-     *
178
-     * @param string $tagName
179
-     *   The tag for which to decrement
180
-     *
181
-     * @param int $step
182
-     *
183
-     * @param int $strategy
184
-     *
185
-     * @return bool
186
-     *   True if the item was successfully decremented. False if there was an error.
187
-     * @throws InvalidArgumentException
188
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
189
-     *   MUST be thrown.
190
-     *
191
-     */
192
-    public function decrementItemsByTag(string $tagName, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
175
+	/**
176
+	 * Decrement the items from the pool by tag.
177
+	 *
178
+	 * @param string $tagName
179
+	 *   The tag for which to decrement
180
+	 *
181
+	 * @param int $step
182
+	 *
183
+	 * @param int $strategy
184
+	 *
185
+	 * @return bool
186
+	 *   True if the item was successfully decremented. False if there was an error.
187
+	 * @throws InvalidArgumentException
188
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
189
+	 *   MUST be thrown.
190
+	 *
191
+	 */
192
+	public function decrementItemsByTag(string $tagName, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
193 193
 
194
-    /**
195
-     * Decrement the items from the pool by one of multiple tag names.
196
-     *
197
-     * @param string[] $tagNames
198
-     *   The tag for which to decrement
199
-     *
200
-     * @param int $step
201
-     *
202
-     * @param int $strategy
203
-     *
204
-     * @return bool
205
-     *   True if the item was successfully decremented. False if there was an error.
206
-     * @throws InvalidArgumentException
207
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
208
-     *   MUST be thrown.
209
-     *
210
-     */
211
-    public function decrementItemsByTags(array $tagNames, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
194
+	/**
195
+	 * Decrement the items from the pool by one of multiple tag names.
196
+	 *
197
+	 * @param string[] $tagNames
198
+	 *   The tag for which to decrement
199
+	 *
200
+	 * @param int $step
201
+	 *
202
+	 * @param int $strategy
203
+	 *
204
+	 * @return bool
205
+	 *   True if the item was successfully decremented. False if there was an error.
206
+	 * @throws InvalidArgumentException
207
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
208
+	 *   MUST be thrown.
209
+	 *
210
+	 */
211
+	public function decrementItemsByTags(array $tagNames, int $step = 1, int $strategy = self::TAG_STRATEGY_ONE): bool;
212 212
 
213
-    /**
214
-     * Decrement the items from the pool by tag.
215
-     *
216
-     * @param string $tagName
217
-     *   The tag for which to append
218
-     *
219
-     * @param array<mixed>|string $data
220
-     *
221
-     * @param int $strategy
222
-     *
223
-     * @return bool
224
-     *   True if the item was successfully appended. False if there was an error.
225
-     * @throws InvalidArgumentException
226
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
227
-     *   MUST be thrown.
228
-     *
229
-     */
230
-    public function appendItemsByTag(string $tagName, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
213
+	/**
214
+	 * Decrement the items from the pool by tag.
215
+	 *
216
+	 * @param string $tagName
217
+	 *   The tag for which to append
218
+	 *
219
+	 * @param array<mixed>|string $data
220
+	 *
221
+	 * @param int $strategy
222
+	 *
223
+	 * @return bool
224
+	 *   True if the item was successfully appended. False if there was an error.
225
+	 * @throws InvalidArgumentException
226
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
227
+	 *   MUST be thrown.
228
+	 *
229
+	 */
230
+	public function appendItemsByTag(string $tagName, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
231 231
 
232
-    /**
233
-     * Append the items from the pool by one of multiple tag names.
234
-     *
235
-     * @param string[] $tagNames
236
-     *   The tag for which to append
237
-     *
238
-     * @param array<mixed>|string $data
239
-     *
240
-     * @param int $strategy
241
-     *
242
-     * @return bool
243
-     *   True if the items were successfully appended. False if there was an error.
244
-     * @throws InvalidArgumentException
245
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
246
-     *   MUST be thrown.
247
-     *
248
-     */
249
-    public function appendItemsByTags(array $tagNames, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
232
+	/**
233
+	 * Append the items from the pool by one of multiple tag names.
234
+	 *
235
+	 * @param string[] $tagNames
236
+	 *   The tag for which to append
237
+	 *
238
+	 * @param array<mixed>|string $data
239
+	 *
240
+	 * @param int $strategy
241
+	 *
242
+	 * @return bool
243
+	 *   True if the items were successfully appended. False if there was an error.
244
+	 * @throws InvalidArgumentException
245
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
246
+	 *   MUST be thrown.
247
+	 *
248
+	 */
249
+	public function appendItemsByTags(array $tagNames, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
250 250
 
251
-    /**
252
-     * Prepend the items from the pool by tag.
253
-     *
254
-     * @param string $tagName
255
-     *   The tag for which to prepend
256
-     *
257
-     * @param array<mixed>|string $data
258
-     *
259
-     * @param int $strategy
260
-     *
261
-     * @return bool
262
-     *   True if the item was successfully prepended. False if there was an error.
263
-     * @throws InvalidArgumentException
264
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
265
-     *   MUST be thrown.
266
-     *
267
-     */
268
-    public function prependItemsByTag(string $tagName, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
251
+	/**
252
+	 * Prepend the items from the pool by tag.
253
+	 *
254
+	 * @param string $tagName
255
+	 *   The tag for which to prepend
256
+	 *
257
+	 * @param array<mixed>|string $data
258
+	 *
259
+	 * @param int $strategy
260
+	 *
261
+	 * @return bool
262
+	 *   True if the item was successfully prepended. False if there was an error.
263
+	 * @throws InvalidArgumentException
264
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
265
+	 *   MUST be thrown.
266
+	 *
267
+	 */
268
+	public function prependItemsByTag(string $tagName, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
269 269
 
270
-    /**
271
-     * Prepend the items from the pool by one of multiple tag names.
272
-     *
273
-     * @param string[] $tagNames
274
-     *   The tag for which to prepend
275
-     *
276
-     * @param array<mixed>|string $data
277
-     *
278
-     * @param int $strategy
279
-     *
280
-     * @return bool
281
-     *   True if the item was successfully prepended. False if there was an error.
282
-     * @throws InvalidArgumentException
283
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
284
-     *   MUST be thrown.
285
-     *
286
-     */
287
-    public function prependItemsByTags(array $tagNames, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
270
+	/**
271
+	 * Prepend the items from the pool by one of multiple tag names.
272
+	 *
273
+	 * @param string[] $tagNames
274
+	 *   The tag for which to prepend
275
+	 *
276
+	 * @param array<mixed>|string $data
277
+	 *
278
+	 * @param int $strategy
279
+	 *
280
+	 * @return bool
281
+	 *   True if the item was successfully prepended. False if there was an error.
282
+	 * @throws InvalidArgumentException
283
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
284
+	 *   MUST be thrown.
285
+	 *
286
+	 */
287
+	public function prependItemsByTags(array $tagNames, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
288 288
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
      *   MUST be thrown.
228 228
      *
229 229
      */
230
-    public function appendItemsByTag(string $tagName, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
230
+    public function appendItemsByTag(string $tagName, array | string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
231 231
 
232 232
     /**
233 233
      * Append the items from the pool by one of multiple tag names.
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
      *   MUST be thrown.
247 247
      *
248 248
      */
249
-    public function appendItemsByTags(array $tagNames, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
249
+    public function appendItemsByTags(array $tagNames, array | string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
250 250
 
251 251
     /**
252 252
      * Prepend the items from the pool by tag.
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      *   MUST be thrown.
266 266
      *
267 267
      */
268
-    public function prependItemsByTag(string $tagName, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
268
+    public function prependItemsByTag(string $tagName, array | string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
269 269
 
270 270
     /**
271 271
      * Prepend the items from the pool by one of multiple tag names.
@@ -284,5 +284,5 @@  discard block
 block discarded – undo
284 284
      *   MUST be thrown.
285 285
      *
286 286
      */
287
-    public function prependItemsByTags(array $tagNames, array|string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
287
+    public function prependItemsByTags(array $tagNames, array | string $data, int $strategy = self::TAG_STRATEGY_ONE): bool;
288 288
 }
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Core/Pool/DriverPoolAbstractTrait.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -24,101 +24,101 @@
 block discarded – undo
24 24
 
25 25
 trait DriverPoolAbstractTrait
26 26
 {
27
-    /**
28
-     * @return bool
29
-     */
30
-    abstract protected function driverCheck(): bool;
31
-
32
-    /**
33
-     * @return bool
34
-     */
35
-    abstract protected function driverConnect(): bool;
36
-
37
-    /**
38
-     * @param ExtendedCacheItemInterface $item
39
-     * @return ?array<string, mixed>
40
-     */
41
-    abstract protected function driverRead(ExtendedCacheItemInterface $item): ?array;
42
-
43
-    /**
44
-     * @param ExtendedCacheItemInterface ...$items
45
-     * @return array<array<string, mixed>>
46
-     * @throws PhpfastcacheUnsupportedMethodException
47
-     */
48
-    protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array
49
-    {
50
-        throw new PhpfastcacheUnsupportedMethodException();
51
-    }
52
-
53
-    /**
54
-     * @return \Traversable<int, string>
55
-     * @throws PhpfastcacheUnsupportedMethodException
56
-     */
57
-    protected function driverReadAllKeys(string $pattern = ''): iterable
58
-    {
59
-        throw new PhpfastcacheUnsupportedMethodException(
60
-            sprintf(
61
-                'The "readAll" operation is unsupported by the the "%s" driver. See the Wiki for more information at %s',
62
-                $this->getDriverName(),
63
-                Wiki::FETCH_ALL_KEY_URL,
64
-            )
65
-        );
66
-    }
67
-
68
-    /**
69
-     * @param ExtendedCacheItemInterface $item
70
-     * @return bool
71
-     */
72
-    abstract protected function driverWrite(ExtendedCacheItemInterface $item): bool;
73
-
74
-    /**
75
-     * @param ExtendedCacheItemInterface ...$item
76
-     * @return bool
77
-     * @throws PhpfastcacheUnsupportedMethodException
78
-     */
79
-    protected function driverWriteMultiple(ExtendedCacheItemInterface ...$item): bool
80
-    {
81
-        /**
82
-         * @todo Implement bulk writes to be for v10:
83
-         * For methods commit() and saveMultiple()
84
-         */
85
-        throw new PhpfastcacheUnsupportedMethodException();
86
-    }
87
-
88
-
89
-    /**
90
-     * @param string $key
91
-     * @param string $encodedKey
92
-     * @return bool
93
-     */
94
-    abstract protected function driverDelete(string $key, string $encodedKey): bool;
95
-
96
-    /**
97
-     * @param string[] $keys
98
-     * @return bool
99
-     * @throws PhpfastcacheUnsupportedMethodException
100
-     */
101
-    protected function driverDeleteMultiple(array $keys): bool
102
-    {
103
-        throw new PhpfastcacheUnsupportedMethodException();
104
-    }
105
-
106
-    /**
107
-     * @return bool
108
-     */
109
-    abstract protected function driverClear(): bool;
110
-
111
-    /**
112
-     * @param CacheItemInterface $item
113
-     * @param string $expectedClassType
114
-     * @throws PhpfastcacheInvalidArgumentException
115
-     */
116
-    protected function assertCacheItemType(CacheItemInterface $item, string $expectedClassType): void
117
-    {
118
-        if (!($item instanceof $expectedClassType)) {
119
-            throw new PhpfastcacheInvalidArgumentException(
120
-                \sprintf('Cross-driver type confusion detected: Expected "%s" object, got "%s"', $expectedClassType, $item::class)
121
-            );
122
-        }
123
-    }
27
+	/**
28
+	 * @return bool
29
+	 */
30
+	abstract protected function driverCheck(): bool;
31
+
32
+	/**
33
+	 * @return bool
34
+	 */
35
+	abstract protected function driverConnect(): bool;
36
+
37
+	/**
38
+	 * @param ExtendedCacheItemInterface $item
39
+	 * @return ?array<string, mixed>
40
+	 */
41
+	abstract protected function driverRead(ExtendedCacheItemInterface $item): ?array;
42
+
43
+	/**
44
+	 * @param ExtendedCacheItemInterface ...$items
45
+	 * @return array<array<string, mixed>>
46
+	 * @throws PhpfastcacheUnsupportedMethodException
47
+	 */
48
+	protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array
49
+	{
50
+		throw new PhpfastcacheUnsupportedMethodException();
51
+	}
52
+
53
+	/**
54
+	 * @return \Traversable<int, string>
55
+	 * @throws PhpfastcacheUnsupportedMethodException
56
+	 */
57
+	protected function driverReadAllKeys(string $pattern = ''): iterable
58
+	{
59
+		throw new PhpfastcacheUnsupportedMethodException(
60
+			sprintf(
61
+				'The "readAll" operation is unsupported by the the "%s" driver. See the Wiki for more information at %s',
62
+				$this->getDriverName(),
63
+				Wiki::FETCH_ALL_KEY_URL,
64
+			)
65
+		);
66
+	}
67
+
68
+	/**
69
+	 * @param ExtendedCacheItemInterface $item
70
+	 * @return bool
71
+	 */
72
+	abstract protected function driverWrite(ExtendedCacheItemInterface $item): bool;
73
+
74
+	/**
75
+	 * @param ExtendedCacheItemInterface ...$item
76
+	 * @return bool
77
+	 * @throws PhpfastcacheUnsupportedMethodException
78
+	 */
79
+	protected function driverWriteMultiple(ExtendedCacheItemInterface ...$item): bool
80
+	{
81
+		/**
82
+		 * @todo Implement bulk writes to be for v10:
83
+		 * For methods commit() and saveMultiple()
84
+		 */
85
+		throw new PhpfastcacheUnsupportedMethodException();
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param string $key
91
+	 * @param string $encodedKey
92
+	 * @return bool
93
+	 */
94
+	abstract protected function driverDelete(string $key, string $encodedKey): bool;
95
+
96
+	/**
97
+	 * @param string[] $keys
98
+	 * @return bool
99
+	 * @throws PhpfastcacheUnsupportedMethodException
100
+	 */
101
+	protected function driverDeleteMultiple(array $keys): bool
102
+	{
103
+		throw new PhpfastcacheUnsupportedMethodException();
104
+	}
105
+
106
+	/**
107
+	 * @return bool
108
+	 */
109
+	abstract protected function driverClear(): bool;
110
+
111
+	/**
112
+	 * @param CacheItemInterface $item
113
+	 * @param string $expectedClassType
114
+	 * @throws PhpfastcacheInvalidArgumentException
115
+	 */
116
+	protected function assertCacheItemType(CacheItemInterface $item, string $expectedClassType): void
117
+	{
118
+		if (!($item instanceof $expectedClassType)) {
119
+			throw new PhpfastcacheInvalidArgumentException(
120
+				\sprintf('Cross-driver type confusion detected: Expected "%s" object, got "%s"', $expectedClassType, $item::class)
121
+			);
122
+		}
123
+	}
124 124
 }
Please login to merge, or discard this patch.
phpfastcache/phpfastcache/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php 3 patches
Indentation   +276 added lines, -276 removed lines patch added patch discarded remove patch
@@ -30,285 +30,285 @@
 block discarded – undo
30 30
  */
31 31
 trait IOHelperTrait
32 32
 {
33
-    use TaggableCacheItemPoolTrait;
34
-
35
-    /**
36
-     * @var array<string, string>
37
-     */
38
-    public array $tmp = [];
39
-
40
-    /**
41
-     * Provide a generic getStats() method
42
-     * for files-based drivers
43
-     * @return DriverStatistic
44
-     * @throws PhpfastcacheIOException
45
-     * @throws PhpfastcacheInvalidArgumentException
46
-     */
47
-    public function getStats(): DriverStatistic
48
-    {
49
-        $stat = new DriverStatistic();
50
-        $path = $this->getFilePath(false);
51
-
52
-        if (!is_dir($path)) {
53
-            throw new PhpfastcacheIOException("Can't read PATH:" . $path);
54
-        }
55
-        $stat->setSize(Directory::dirSize($path))
56
-            ->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path))
57
-            ->setRawData(
58
-                [
59
-                    'tmp' => $this->tmp,
60
-                ]
61
-            );
62
-
63
-        if ($this->getConfig()->isUseStaticItemCaching()) {
64
-            $stat->setData(implode(', ', \array_keys($this->itemInstances)));
65
-        } else {
66
-            $stat->setData('No data available since static item caching option (useStaticItemCaching) is disabled.');
67
-        }
68
-
69
-        return $stat;
70
-    }
71
-
72
-    /**
73
-     * @param string|bool $keyword
74
-     * @param bool $skip
75
-     * @return string
76
-     * @throws PhpfastcacheIOException
77
-     * @throws PhpfastcacheInvalidArgumentException
78
-     */
79
-    protected function getFilePath(string|bool $keyword, bool $skip = false): string
80
-    {
81
-        $path = $this->getPath();
82
-
83
-        if ($keyword === false) {
84
-            return $path;
85
-        }
86
-
87
-        $filename = $this->encodeFilename($keyword);
88
-        $folder = \substr($filename, 0, 2) . DIRECTORY_SEPARATOR . \substr($filename, 2, 2);
89
-        $path = \rtrim($path, '/\\') . DIRECTORY_SEPARATOR . $folder;
90
-
91
-        /**
92
-         * Skip Create Sub Folders;
93
-         */
94
-        if (!$skip && !\is_dir($path) && @!\mkdir($path, $this->getDefaultChmod(), true) && !\is_dir($path)) {
95
-            throw new PhpfastcacheIOException(
96
-                'Path "' . $path . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !'
97
-            );
98
-        }
99
-
100
-        return $path . \DIRECTORY_SEPARATOR . $filename . '.' . $this->getConfig()->getCacheFileExtension();
101
-    }
102
-
103
-    /**
104
-     * @param bool $readonly
105
-     * @return string
106
-     * @throws PhpfastcacheIOException
107
-     * @throws PhpfastcacheInvalidArgumentException
108
-     */
109
-    public function getPath(bool $readonly = false): string
110
-    {
111
-        $tmpDir = \rtrim(\ini_get('upload_tmp_dir') ?: \sys_get_temp_dir(), '\\/') . DIRECTORY_SEPARATOR . 'phpfastcache';
112
-        $httpHost = $this->getConfig()->getSuperGlobalAccessor()('SERVER', 'HTTP_HOST');
113
-        $securityKey = $this->buildSecurityKey($httpHost);
114
-
115
-        /**
116
-         * Extends the temporary directory
117
-         * with the security key and the driver name
118
-         */
119
-        $tmpDir = \rtrim($tmpDir, '/') . DIRECTORY_SEPARATOR;
120
-
121
-        if (empty($this->getConfig()->getPath())) {
122
-            $path = $tmpDir;
123
-        } else {
124
-            $path = \rtrim($this->getConfig()->getPath(), '/') . DIRECTORY_SEPARATOR;
125
-        }
126
-
127
-        $pathSuffix = $securityKey . DIRECTORY_SEPARATOR . $this->getDriverName();
128
-        $fullPath = Directory::getAbsolutePath($path . $pathSuffix);
129
-        $fullPathTmp = Directory::getAbsolutePath($tmpDir . $pathSuffix);
130
-
131
-        $this->mkdir($fullPath, $fullPathTmp);
132
-
133
-        /**
134
-         * In readonly mode we only attempt
135
-         * to verify if the directory exists
136
-         * or not, if it does not then we
137
-         * return the temp dir
138
-         */
139
-        if ($readonly) {
140
-            if ($this->getConfig()->isAutoTmpFallback() && (!@\file_exists($fullPath) || !@\is_writable($fullPath))) {
141
-                return $fullPathTmp;
142
-            }
143
-            return $fullPath;
144
-        }
145
-
146
-        return realpath($fullPath);
147
-    }
148
-
149
-    protected function buildSecurityKey(?string $httpHost): string
150
-    {
151
-        $securityKey = $this->getConfig()->getSecurityKey();
152
-        if (!$securityKey || \mb_strtolower($securityKey) === 'auto') {
153
-            if (isset($httpHost)) {
154
-                $securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $httpHost)));
155
-            } else {
156
-                $securityKey = (SapiDetector::isWebScript() ? 'web' : 'cli');
157
-            }
158
-        }
159
-
160
-        if (!empty($securityKey)) {
161
-            $securityKey .= '/';
162
-        }
163
-
164
-        return static::cleanFileName($securityKey);
165
-    }
166
-
167
-    /**
168
-     * @throws PhpfastcacheIOException
169
-     */
170
-    protected function mkdir(string $fullPath, string $fullPathTmp): void
171
-    {
172
-        $fullPathHash = $this->getConfig()->getDefaultFileNameHashFunction()($fullPath);
173
-
174
-        if (!isset($this->tmp[$fullPathHash]) || (!@\file_exists($fullPath) || !@\is_writable($fullPath))) {
175
-            if (!@\file_exists($fullPath)) {
176
-                if (@mkdir($fullPath, $this->getDefaultChmod(), true) === false && !\is_dir($fullPath)) {
177
-                    throw new PhpfastcacheIOException('The directory ' . $fullPath . ' could not be created.');
178
-                }
179
-            } elseif (!@\is_writable($fullPath) && !@\chmod($fullPath, $this->getDefaultChmod()) && $this->getConfig()->isAutoTmpFallback()) {
180
-                /**
181
-                 * Switch back to tmp dir
182
-                 * again if the path is not writable
183
-                 */
184
-                $fullPath = $fullPathTmp;
185
-                if (!@\file_exists($fullPath) && @\mkdir($fullPath, $this->getDefaultChmod(), true) && !\is_dir($fullPath)) {
186
-                    throw new PhpfastcacheIOException('The directory ' . $fullPath . ' could not be created.');
187
-                }
188
-            }
189
-
190
-            /**
191
-             * In case there is no directory
192
-             * writable including the temporary
193
-             * one, we must throw an exception
194
-             */
195
-            if (!@\file_exists($fullPath) || !@\is_writable($fullPath)) {
196
-                throw new PhpfastcacheIOException(
197
-                    'Path "' . $fullPath . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !'
198
-                );
199
-            }
200
-
201
-            $this->tmp[$fullPathHash] = $fullPath;
202
-        }
203
-    }
204
-
205
-    /**
206
-     * @param string $filename
207
-     * @return string
208
-     */
209
-    protected static function cleanFileName(string $filename): string
210
-    {
211
-        $regex = [
212
-            '/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/',
213
-            '/\.$/',
214
-            '/^\./',
215
-        ];
216
-        $replace = ['-', '', ''];
217
-
218
-        return \trim(\preg_replace($regex, $replace, \trim($filename)), '-');
219
-    }
220
-
221
-    /**
222
-     * @return int
223
-     */
224
-    protected function getDefaultChmod(): int
225
-    {
226
-        if (!$this->getConfig()->getDefaultChmod()) {
227
-            return 0777;
228
-        }
229
-
230
-        return $this->getConfig()->getDefaultChmod();
231
-    }
232
-
233
-    /**
234
-     * @param string $keyword
235
-     * @return string
236
-     */
237
-    protected function encodeFilename(string $keyword): string
238
-    {
239
-        return $this->getConfig()->getDefaultFileNameHashFunction()($keyword);
240
-    }
241
-
242
-    /**
243
-     * @param string $file
244
-     * @return string
245
-     * @throws PhpfastcacheIOException
246
-     */
247
-    protected function readFile(string $file): string
248
-    {
249
-        if (!\is_readable($file)) {
250
-            throw new PhpfastcacheIOException("Cannot read file located at: $file");
251
-        }
252
-        if (\function_exists('file_get_contents')) {
253
-            return (string)\file_get_contents($file);
254
-        }
255
-
256
-        $string = '';
257
-
258
-        $fileHandle = @\fopen($file, 'rb');
259
-        while (!\feof($fileHandle)) {
260
-            $line = \fgets($fileHandle);
261
-            $string .= $line;
262
-        }
263
-        \fclose($fileHandle);
264
-
265
-        return $string;
266
-    }
267
-
268
-    /********************
33
+	use TaggableCacheItemPoolTrait;
34
+
35
+	/**
36
+	 * @var array<string, string>
37
+	 */
38
+	public array $tmp = [];
39
+
40
+	/**
41
+	 * Provide a generic getStats() method
42
+	 * for files-based drivers
43
+	 * @return DriverStatistic
44
+	 * @throws PhpfastcacheIOException
45
+	 * @throws PhpfastcacheInvalidArgumentException
46
+	 */
47
+	public function getStats(): DriverStatistic
48
+	{
49
+		$stat = new DriverStatistic();
50
+		$path = $this->getFilePath(false);
51
+
52
+		if (!is_dir($path)) {
53
+			throw new PhpfastcacheIOException("Can't read PATH:" . $path);
54
+		}
55
+		$stat->setSize(Directory::dirSize($path))
56
+			->setInfo('Number of files used to build the cache: ' . Directory::getFileCount($path))
57
+			->setRawData(
58
+				[
59
+					'tmp' => $this->tmp,
60
+				]
61
+			);
62
+
63
+		if ($this->getConfig()->isUseStaticItemCaching()) {
64
+			$stat->setData(implode(', ', \array_keys($this->itemInstances)));
65
+		} else {
66
+			$stat->setData('No data available since static item caching option (useStaticItemCaching) is disabled.');
67
+		}
68
+
69
+		return $stat;
70
+	}
71
+
72
+	/**
73
+	 * @param string|bool $keyword
74
+	 * @param bool $skip
75
+	 * @return string
76
+	 * @throws PhpfastcacheIOException
77
+	 * @throws PhpfastcacheInvalidArgumentException
78
+	 */
79
+	protected function getFilePath(string|bool $keyword, bool $skip = false): string
80
+	{
81
+		$path = $this->getPath();
82
+
83
+		if ($keyword === false) {
84
+			return $path;
85
+		}
86
+
87
+		$filename = $this->encodeFilename($keyword);
88
+		$folder = \substr($filename, 0, 2) . DIRECTORY_SEPARATOR . \substr($filename, 2, 2);
89
+		$path = \rtrim($path, '/\\') . DIRECTORY_SEPARATOR . $folder;
90
+
91
+		/**
92
+		 * Skip Create Sub Folders;
93
+		 */
94
+		if (!$skip && !\is_dir($path) && @!\mkdir($path, $this->getDefaultChmod(), true) && !\is_dir($path)) {
95
+			throw new PhpfastcacheIOException(
96
+				'Path "' . $path . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !'
97
+			);
98
+		}
99
+
100
+		return $path . \DIRECTORY_SEPARATOR . $filename . '.' . $this->getConfig()->getCacheFileExtension();
101
+	}
102
+
103
+	/**
104
+	 * @param bool $readonly
105
+	 * @return string
106
+	 * @throws PhpfastcacheIOException
107
+	 * @throws PhpfastcacheInvalidArgumentException
108
+	 */
109
+	public function getPath(bool $readonly = false): string
110
+	{
111
+		$tmpDir = \rtrim(\ini_get('upload_tmp_dir') ?: \sys_get_temp_dir(), '\\/') . DIRECTORY_SEPARATOR . 'phpfastcache';
112
+		$httpHost = $this->getConfig()->getSuperGlobalAccessor()('SERVER', 'HTTP_HOST');
113
+		$securityKey = $this->buildSecurityKey($httpHost);
114
+
115
+		/**
116
+		 * Extends the temporary directory
117
+		 * with the security key and the driver name
118
+		 */
119
+		$tmpDir = \rtrim($tmpDir, '/') . DIRECTORY_SEPARATOR;
120
+
121
+		if (empty($this->getConfig()->getPath())) {
122
+			$path = $tmpDir;
123
+		} else {
124
+			$path = \rtrim($this->getConfig()->getPath(), '/') . DIRECTORY_SEPARATOR;
125
+		}
126
+
127
+		$pathSuffix = $securityKey . DIRECTORY_SEPARATOR . $this->getDriverName();
128
+		$fullPath = Directory::getAbsolutePath($path . $pathSuffix);
129
+		$fullPathTmp = Directory::getAbsolutePath($tmpDir . $pathSuffix);
130
+
131
+		$this->mkdir($fullPath, $fullPathTmp);
132
+
133
+		/**
134
+		 * In readonly mode we only attempt
135
+		 * to verify if the directory exists
136
+		 * or not, if it does not then we
137
+		 * return the temp dir
138
+		 */
139
+		if ($readonly) {
140
+			if ($this->getConfig()->isAutoTmpFallback() && (!@\file_exists($fullPath) || !@\is_writable($fullPath))) {
141
+				return $fullPathTmp;
142
+			}
143
+			return $fullPath;
144
+		}
145
+
146
+		return realpath($fullPath);
147
+	}
148
+
149
+	protected function buildSecurityKey(?string $httpHost): string
150
+	{
151
+		$securityKey = $this->getConfig()->getSecurityKey();
152
+		if (!$securityKey || \mb_strtolower($securityKey) === 'auto') {
153
+			if (isset($httpHost)) {
154
+				$securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $httpHost)));
155
+			} else {
156
+				$securityKey = (SapiDetector::isWebScript() ? 'web' : 'cli');
157
+			}
158
+		}
159
+
160
+		if (!empty($securityKey)) {
161
+			$securityKey .= '/';
162
+		}
163
+
164
+		return static::cleanFileName($securityKey);
165
+	}
166
+
167
+	/**
168
+	 * @throws PhpfastcacheIOException
169
+	 */
170
+	protected function mkdir(string $fullPath, string $fullPathTmp): void
171
+	{
172
+		$fullPathHash = $this->getConfig()->getDefaultFileNameHashFunction()($fullPath);
173
+
174
+		if (!isset($this->tmp[$fullPathHash]) || (!@\file_exists($fullPath) || !@\is_writable($fullPath))) {
175
+			if (!@\file_exists($fullPath)) {
176
+				if (@mkdir($fullPath, $this->getDefaultChmod(), true) === false && !\is_dir($fullPath)) {
177
+					throw new PhpfastcacheIOException('The directory ' . $fullPath . ' could not be created.');
178
+				}
179
+			} elseif (!@\is_writable($fullPath) && !@\chmod($fullPath, $this->getDefaultChmod()) && $this->getConfig()->isAutoTmpFallback()) {
180
+				/**
181
+				 * Switch back to tmp dir
182
+				 * again if the path is not writable
183
+				 */
184
+				$fullPath = $fullPathTmp;
185
+				if (!@\file_exists($fullPath) && @\mkdir($fullPath, $this->getDefaultChmod(), true) && !\is_dir($fullPath)) {
186
+					throw new PhpfastcacheIOException('The directory ' . $fullPath . ' could not be created.');
187
+				}
188
+			}
189
+
190
+			/**
191
+			 * In case there is no directory
192
+			 * writable including the temporary
193
+			 * one, we must throw an exception
194
+			 */
195
+			if (!@\file_exists($fullPath) || !@\is_writable($fullPath)) {
196
+				throw new PhpfastcacheIOException(
197
+					'Path "' . $fullPath . '" is not writable, please set a chmod 0777 or any writable permission and make sure to make use of an absolute path !'
198
+				);
199
+			}
200
+
201
+			$this->tmp[$fullPathHash] = $fullPath;
202
+		}
203
+	}
204
+
205
+	/**
206
+	 * @param string $filename
207
+	 * @return string
208
+	 */
209
+	protected static function cleanFileName(string $filename): string
210
+	{
211
+		$regex = [
212
+			'/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/',
213
+			'/\.$/',
214
+			'/^\./',
215
+		];
216
+		$replace = ['-', '', ''];
217
+
218
+		return \trim(\preg_replace($regex, $replace, \trim($filename)), '-');
219
+	}
220
+
221
+	/**
222
+	 * @return int
223
+	 */
224
+	protected function getDefaultChmod(): int
225
+	{
226
+		if (!$this->getConfig()->getDefaultChmod()) {
227
+			return 0777;
228
+		}
229
+
230
+		return $this->getConfig()->getDefaultChmod();
231
+	}
232
+
233
+	/**
234
+	 * @param string $keyword
235
+	 * @return string
236
+	 */
237
+	protected function encodeFilename(string $keyword): string
238
+	{
239
+		return $this->getConfig()->getDefaultFileNameHashFunction()($keyword);
240
+	}
241
+
242
+	/**
243
+	 * @param string $file
244
+	 * @return string
245
+	 * @throws PhpfastcacheIOException
246
+	 */
247
+	protected function readFile(string $file): string
248
+	{
249
+		if (!\is_readable($file)) {
250
+			throw new PhpfastcacheIOException("Cannot read file located at: $file");
251
+		}
252
+		if (\function_exists('file_get_contents')) {
253
+			return (string)\file_get_contents($file);
254
+		}
255
+
256
+		$string = '';
257
+
258
+		$fileHandle = @\fopen($file, 'rb');
259
+		while (!\feof($fileHandle)) {
260
+			$line = \fgets($fileHandle);
261
+			$string .= $line;
262
+		}
263
+		\fclose($fileHandle);
264
+
265
+		return $string;
266
+	}
267
+
268
+	/********************
269 269
      *
270 270
      * PSR-6 Extended Methods
271 271
      *
272 272
      *******************/
273 273
 
274
-    /**
275
-     * @param string $file
276
-     * @param string $data
277
-     * @param bool $secureFileManipulation
278
-     * @return bool
279
-     * @throws PhpfastcacheIOException
280
-     * @throws \Exception
281
-     */
282
-    protected function writeFile(string $file, string $data, bool $secureFileManipulation = false): bool
283
-    {
284
-        $this->eventManager->dispatch(Event::CACHE_WRITE_FILE_ON_DISK, $this, $file, $secureFileManipulation);
285
-
286
-        if ($secureFileManipulation) {
287
-            $tmpFilename = Directory::getAbsolutePath(
288
-                dirname($file) . \DIRECTORY_SEPARATOR . 'tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()(
289
-                    \bin2hex(\random_bytes(16))
290
-                )
291
-            ) . '.' . $this->getConfig()->getCacheFileExtension() . \random_int(1000, 9999);
292
-
293
-            $handle = \fopen($tmpFilename, 'w+b');
294
-            if (\is_resource($handle)) {
295
-                \flock($handle, \LOCK_EX);
296
-                $octetWritten = fwrite($handle, $data);
297
-                \flock($handle, \LOCK_UN);
298
-                \fclose($handle);
299
-            }
300
-
301
-            if (!\rename($tmpFilename, $file)) {
302
-                throw new PhpfastcacheIOException(\sprintf('Failed to rename %s to %s', $tmpFilename, $file));
303
-            }
304
-        } else {
305
-            $handle = \fopen($file, 'w+b');
306
-            if (\is_resource($handle)) {
307
-                $octetWritten = \fwrite($handle, $data);
308
-                \fclose($handle);
309
-            }
310
-        }
311
-
312
-        return (bool)($octetWritten ?? false);
313
-    }
274
+	/**
275
+	 * @param string $file
276
+	 * @param string $data
277
+	 * @param bool $secureFileManipulation
278
+	 * @return bool
279
+	 * @throws PhpfastcacheIOException
280
+	 * @throws \Exception
281
+	 */
282
+	protected function writeFile(string $file, string $data, bool $secureFileManipulation = false): bool
283
+	{
284
+		$this->eventManager->dispatch(Event::CACHE_WRITE_FILE_ON_DISK, $this, $file, $secureFileManipulation);
285
+
286
+		if ($secureFileManipulation) {
287
+			$tmpFilename = Directory::getAbsolutePath(
288
+				dirname($file) . \DIRECTORY_SEPARATOR . 'tmp_' . $this->getConfig()->getDefaultFileNameHashFunction()(
289
+					\bin2hex(\random_bytes(16))
290
+				)
291
+			) . '.' . $this->getConfig()->getCacheFileExtension() . \random_int(1000, 9999);
292
+
293
+			$handle = \fopen($tmpFilename, 'w+b');
294
+			if (\is_resource($handle)) {
295
+				\flock($handle, \LOCK_EX);
296
+				$octetWritten = fwrite($handle, $data);
297
+				\flock($handle, \LOCK_UN);
298
+				\fclose($handle);
299
+			}
300
+
301
+			if (!\rename($tmpFilename, $file)) {
302
+				throw new PhpfastcacheIOException(\sprintf('Failed to rename %s to %s', $tmpFilename, $file));
303
+			}
304
+		} else {
305
+			$handle = \fopen($file, 'w+b');
306
+			if (\is_resource($handle)) {
307
+				$octetWritten = \fwrite($handle, $data);
308
+				\fclose($handle);
309
+			}
310
+		}
311
+
312
+		return (bool)($octetWritten ?? false);
313
+	}
314 314
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * @throws PhpfastcacheIOException
77 77
      * @throws PhpfastcacheInvalidArgumentException
78 78
      */
79
-    protected function getFilePath(string|bool $keyword, bool $skip = false): string
79
+    protected function getFilePath(string | bool $keyword, bool $skip = false): string
80 80
     {
81 81
         $path = $this->getPath();
82 82
 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
             throw new PhpfastcacheIOException("Cannot read file located at: $file");
251 251
         }
252 252
         if (\function_exists('file_get_contents')) {
253
-            return (string)\file_get_contents($file);
253
+            return (string) \file_get_contents($file);
254 254
         }
255 255
 
256 256
         $string = '';
@@ -309,6 +309,6 @@  discard block
 block discarded – undo
309 309
             }
310 310
         }
311 311
 
312
-        return (bool)($octetWritten ?? false);
312
+        return (bool) ($octetWritten ?? false);
313 313
     }
314 314
 }
Please login to merge, or discard this patch.
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -62,7 +62,8 @@  discard block
 block discarded – undo
62 62
 
63 63
         if ($this->getConfig()->isUseStaticItemCaching()) {
64 64
             $stat->setData(implode(', ', \array_keys($this->itemInstances)));
65
-        } else {
65
+        }
66
+        else {
66 67
             $stat->setData('No data available since static item caching option (useStaticItemCaching) is disabled.');
67 68
         }
68 69
 
@@ -120,7 +121,8 @@  discard block
 block discarded – undo
120 121
 
121 122
         if (empty($this->getConfig()->getPath())) {
122 123
             $path = $tmpDir;
123
-        } else {
124
+        }
125
+        else {
124 126
             $path = \rtrim($this->getConfig()->getPath(), '/') . DIRECTORY_SEPARATOR;
125 127
         }
126 128
 
@@ -152,7 +154,8 @@  discard block
 block discarded – undo
152 154
         if (!$securityKey || \mb_strtolower($securityKey) === 'auto') {
153 155
             if (isset($httpHost)) {
154 156
                 $securityKey = \preg_replace('/^www./', '', \strtolower(\str_replace(':', '_', $httpHost)));
155
-            } else {
157
+            }
158
+            else {
156 159
                 $securityKey = (SapiDetector::isWebScript() ? 'web' : 'cli');
157 160
             }
158 161
         }
@@ -176,7 +179,8 @@  discard block
 block discarded – undo
176 179
                 if (@mkdir($fullPath, $this->getDefaultChmod(), true) === false && !\is_dir($fullPath)) {
177 180
                     throw new PhpfastcacheIOException('The directory ' . $fullPath . ' could not be created.');
178 181
                 }
179
-            } elseif (!@\is_writable($fullPath) && !@\chmod($fullPath, $this->getDefaultChmod()) && $this->getConfig()->isAutoTmpFallback()) {
182
+            }
183
+            elseif (!@\is_writable($fullPath) && !@\chmod($fullPath, $this->getDefaultChmod()) && $this->getConfig()->isAutoTmpFallback()) {
180 184
                 /**
181 185
                  * Switch back to tmp dir
182 186
                  * again if the path is not writable
@@ -301,7 +305,8 @@  discard block
 block discarded – undo
301 305
             if (!\rename($tmpFilename, $file)) {
302 306
                 throw new PhpfastcacheIOException(\sprintf('Failed to rename %s to %s', $tmpFilename, $file));
303 307
             }
304
-        } else {
308
+        }
309
+        else {
305 310
             $handle = \fopen($file, 'w+b');
306 311
             if (\is_resource($handle)) {
307 312
                 $octetWritten = \fwrite($handle, $data);
Please login to merge, or discard this patch.
phpfastcache/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php 2 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -36,196 +36,196 @@
 block discarded – undo
36 36
  */
37 37
 interface ExtendedCacheItemPoolInterface extends CacheItemPoolInterface, EventManagerDispatcherInterface, ClassNamespaceResolverInterface, TaggableCacheItemPoolInterface
38 38
 {
39
-    public const DRIVER_CHECK_FAILURE = '%s is not installed or is misconfigured, cannot continue. 
39
+	public const DRIVER_CHECK_FAILURE = '%s is not installed or is misconfigured, cannot continue. 
40 40
     Also, please verify the suggested dependencies in composer because as of the V6, 3rd party libraries are no longer required.%s';
41 41
 
42
-    public const DRIVER_CONNECT_FAILURE = '%s failed to connect with the following error message: "%s" line %d in %s.';
43
-
44
-    public const DRIVER_KEY_WRAPPER_INDEX = 'k';
45
-
46
-    public const DRIVER_DATA_WRAPPER_INDEX = 'd';
47
-
48
-    /**
49
-     * Expiration date Index
50
-     */
51
-    public const DRIVER_EDATE_WRAPPER_INDEX = 'e';
52
-
53
-    /**
54
-     * Creation date Index
55
-     */
56
-    public const DRIVER_CDATE_WRAPPER_INDEX = 'c';
57
-
58
-    /**
59
-     * Modification date Index
60
-     */
61
-    public const DRIVER_MDATE_WRAPPER_INDEX = 'm';
62
-
63
-    /**
64
-     * Hard-limit count  of items returns by getAllItems()
65
-     */
66
-    public const MAX_ALL_KEYS_COUNT = 9999;
67
-
68
-    /**
69
-     * Return the config class name
70
-     * @return string
71
-     */
72
-    public static function getConfigClass(): string;
73
-
74
-    /**
75
-     * Return the item class name
76
-     * @return string
77
-     */
78
-    public static function getItemClass(): string;
79
-
80
-    /**
81
-     * @param string $key
82
-     * @return string
83
-     */
84
-    public function getEncodedKey(string $key): string;
85
-
86
-    /**
87
-     * @return ConfigurationOptionInterface
88
-     */
89
-    public function getConfig(): ConfigurationOptionInterface;
90
-
91
-    /**
92
-     * @return ConfigurationOptionInterface
93
-     */
94
-    public function getDefaultConfig(): ConfigurationOptionInterface;
95
-
96
-    /**
97
-     * @return string
98
-     */
99
-    public function getDriverName(): string;
100
-
101
-    /**
102
-     * @return mixed
103
-     */
104
-    public function getInstanceId(): string;
105
-
106
-    /**
107
-     * [Phpfastcache phpDoc Override]
108
-     * Returns a Cache Item representing the specified key.
109
-     *
110
-     * This method must always return a CacheItemInterface object, even in case of
111
-     * a cache miss. It MUST NOT return null.
112
-     *
113
-     * @param string $key
114
-     *   The key for which to return the corresponding Cache Item.
115
-     *
116
-     * @return ExtendedCacheItemInterface
117
-     *   The corresponding Cache Item.
118
-     * @throws PhpfastcacheInvalidArgumentException
119
-     *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
120
-     *   MUST be thrown.
121
-     *
122
-     */
123
-    public function getItem(string $key): ExtendedCacheItemInterface;
124
-
125
-    /**
126
-     * [Phpfastcache phpDoc Override]
127
-     * Returns a traversable set of cache items.
128
-     *
129
-     * @param string[] $keys
130
-     * An indexed array of keys of items to retrieve.
131
-     *
132
-     * @return iterable<ExtendedCacheItemInterface>
133
-     *   A traversable collection of Cache Items keyed by the cache keys of
134
-     *   each item. A Cache item will be returned for each key, even if that
135
-     *   key is not found. However, if no keys are specified then an empty
136
-     *   traversable MUST be returned instead.
137
-     * @throws InvalidArgumentException
138
-     *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
139
-     *   MUST be thrown.
140
-     *
141
-     */
142
-    public function getItems(array $keys = []): iterable;
143
-
144
-    /**
145
-     * Returns the WHOLE cache as a traversable set of cache items.
146
-     * A hard-limit of 9999 items is defined internally to prevent
147
-     * serious performances issues of your application.
148
-     * @see ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT
149
-     *
150
-     * @param string $pattern
151
-     * An optional pattern supported by a limited range of drivers.
152
-     * If this parameter is unsupported by the driver, a PhpfastcacheInvalidArgumentException will be thrown.
153
-     *
154
-     * @return iterable<ExtendedCacheItemInterface>
155
-     *   A traversable collection of Cache Items keyed by the cache keys of
156
-     *   each item. However, if no keys are returned by the backend then an empty
157
-     *   traversable WILL be returned instead.
158
-     *
159
-     * @throws PhpfastcacheInvalidArgumentException If the driver does not support the $pattern argument
160
-     * @throws PhpfastcacheUnsupportedMethodException If the driver does not permit to list all the keys through this implementation.
161
-     */
162
-    public function getAllItems(string $pattern = ''): iterable;
163
-
164
-    /**
165
-     * Returns A json string that represents an array of items.
166
-     *
167
-     * @param array<string> $keys An indexed array of keys of items to retrieve.
168
-     * @param int $options \json_encode() options
169
-     * @param int $depth \json_encode() depth
170
-     *
171
-     * @return string
172
-     * @throws InvalidArgumentException
173
-     *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
174
-     *   MUST be thrown.
175
-     *
176
-     */
177
-    public function getItemsAsJsonString(array $keys = [], int $options = \JSON_THROW_ON_ERROR, int $depth = 512): string;
178
-
179
-    public function setItem(CacheItemInterface $item): static;
180
-
181
-    public function getStats(): DriverStatistic;
182
-
183
-    /**
184
-     * Get a quick help guide
185
-     * about the current driver
186
-     */
187
-    public function getHelp(): string;
188
-
189
-    public function detachItem(CacheItemInterface $item): static;
190
-
191
-    public function detachAllItems(): static;
192
-
193
-    public function attachItem(CacheItemInterface $item): static;
194
-
195
-    /**
196
-     * Returns true if the item exists, is attached and the Spl Hash matches
197
-     * Returns false if the item exists, is attached and the Spl Hash mismatches
198
-     * Returns null if the item does not exist
199
-     *
200
-     * @param CacheItemInterface $item
201
-     * @return bool
202
-     * @throws PhpfastcacheLogicException
203
-     */
204
-    public function isAttached(CacheItemInterface $item): bool;
205
-
206
-    /**
207
-     * Persists a cache item immediately.
208
-     *
209
-     * @param ExtendedCacheItemInterface|CacheItemInterface $item
210
-     *   The cache item to save.
211
-     *
212
-     * @return bool
213
-     *   True if the item was successfully persisted. False if there was an error.
214
-     */
215
-    public function save(ExtendedCacheItemInterface|CacheItemInterface $item): bool;
216
-
217
-    /**
218
-     * Save multiple items, possible uses:
219
-     *  saveMultiple([$item1, $item2, $item3]);
220
-     *  saveMultiple($item1, $item2, $item3);
221
-     *
222
-     * @param ExtendedCacheItemInterface[] $items
223
-     * @return bool
224
-     */
225
-    public function saveMultiple(ExtendedCacheItemInterface ...$items): bool;
226
-
227
-    /**
228
-     * @return DriverIO
229
-     */
230
-    public function getIO(): DriverIO;
42
+	public const DRIVER_CONNECT_FAILURE = '%s failed to connect with the following error message: "%s" line %d in %s.';
43
+
44
+	public const DRIVER_KEY_WRAPPER_INDEX = 'k';
45
+
46
+	public const DRIVER_DATA_WRAPPER_INDEX = 'd';
47
+
48
+	/**
49
+	 * Expiration date Index
50
+	 */
51
+	public const DRIVER_EDATE_WRAPPER_INDEX = 'e';
52
+
53
+	/**
54
+	 * Creation date Index
55
+	 */
56
+	public const DRIVER_CDATE_WRAPPER_INDEX = 'c';
57
+
58
+	/**
59
+	 * Modification date Index
60
+	 */
61
+	public const DRIVER_MDATE_WRAPPER_INDEX = 'm';
62
+
63
+	/**
64
+	 * Hard-limit count  of items returns by getAllItems()
65
+	 */
66
+	public const MAX_ALL_KEYS_COUNT = 9999;
67
+
68
+	/**
69
+	 * Return the config class name
70
+	 * @return string
71
+	 */
72
+	public static function getConfigClass(): string;
73
+
74
+	/**
75
+	 * Return the item class name
76
+	 * @return string
77
+	 */
78
+	public static function getItemClass(): string;
79
+
80
+	/**
81
+	 * @param string $key
82
+	 * @return string
83
+	 */
84
+	public function getEncodedKey(string $key): string;
85
+
86
+	/**
87
+	 * @return ConfigurationOptionInterface
88
+	 */
89
+	public function getConfig(): ConfigurationOptionInterface;
90
+
91
+	/**
92
+	 * @return ConfigurationOptionInterface
93
+	 */
94
+	public function getDefaultConfig(): ConfigurationOptionInterface;
95
+
96
+	/**
97
+	 * @return string
98
+	 */
99
+	public function getDriverName(): string;
100
+
101
+	/**
102
+	 * @return mixed
103
+	 */
104
+	public function getInstanceId(): string;
105
+
106
+	/**
107
+	 * [Phpfastcache phpDoc Override]
108
+	 * Returns a Cache Item representing the specified key.
109
+	 *
110
+	 * This method must always return a CacheItemInterface object, even in case of
111
+	 * a cache miss. It MUST NOT return null.
112
+	 *
113
+	 * @param string $key
114
+	 *   The key for which to return the corresponding Cache Item.
115
+	 *
116
+	 * @return ExtendedCacheItemInterface
117
+	 *   The corresponding Cache Item.
118
+	 * @throws PhpfastcacheInvalidArgumentException
119
+	 *   If the $key string is not a legal value a phpfastcacheInvalidArgumentException
120
+	 *   MUST be thrown.
121
+	 *
122
+	 */
123
+	public function getItem(string $key): ExtendedCacheItemInterface;
124
+
125
+	/**
126
+	 * [Phpfastcache phpDoc Override]
127
+	 * Returns a traversable set of cache items.
128
+	 *
129
+	 * @param string[] $keys
130
+	 * An indexed array of keys of items to retrieve.
131
+	 *
132
+	 * @return iterable<ExtendedCacheItemInterface>
133
+	 *   A traversable collection of Cache Items keyed by the cache keys of
134
+	 *   each item. A Cache item will be returned for each key, even if that
135
+	 *   key is not found. However, if no keys are specified then an empty
136
+	 *   traversable MUST be returned instead.
137
+	 * @throws InvalidArgumentException
138
+	 *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
139
+	 *   MUST be thrown.
140
+	 *
141
+	 */
142
+	public function getItems(array $keys = []): iterable;
143
+
144
+	/**
145
+	 * Returns the WHOLE cache as a traversable set of cache items.
146
+	 * A hard-limit of 9999 items is defined internally to prevent
147
+	 * serious performances issues of your application.
148
+	 * @see ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT
149
+	 *
150
+	 * @param string $pattern
151
+	 * An optional pattern supported by a limited range of drivers.
152
+	 * If this parameter is unsupported by the driver, a PhpfastcacheInvalidArgumentException will be thrown.
153
+	 *
154
+	 * @return iterable<ExtendedCacheItemInterface>
155
+	 *   A traversable collection of Cache Items keyed by the cache keys of
156
+	 *   each item. However, if no keys are returned by the backend then an empty
157
+	 *   traversable WILL be returned instead.
158
+	 *
159
+	 * @throws PhpfastcacheInvalidArgumentException If the driver does not support the $pattern argument
160
+	 * @throws PhpfastcacheUnsupportedMethodException If the driver does not permit to list all the keys through this implementation.
161
+	 */
162
+	public function getAllItems(string $pattern = ''): iterable;
163
+
164
+	/**
165
+	 * Returns A json string that represents an array of items.
166
+	 *
167
+	 * @param array<string> $keys An indexed array of keys of items to retrieve.
168
+	 * @param int $options \json_encode() options
169
+	 * @param int $depth \json_encode() depth
170
+	 *
171
+	 * @return string
172
+	 * @throws InvalidArgumentException
173
+	 *   If any of the keys in $keys are not a legal value a phpfastcacheInvalidArgumentException
174
+	 *   MUST be thrown.
175
+	 *
176
+	 */
177
+	public function getItemsAsJsonString(array $keys = [], int $options = \JSON_THROW_ON_ERROR, int $depth = 512): string;
178
+
179
+	public function setItem(CacheItemInterface $item): static;
180
+
181
+	public function getStats(): DriverStatistic;
182
+
183
+	/**
184
+	 * Get a quick help guide
185
+	 * about the current driver
186
+	 */
187
+	public function getHelp(): string;
188
+
189
+	public function detachItem(CacheItemInterface $item): static;
190
+
191
+	public function detachAllItems(): static;
192
+
193
+	public function attachItem(CacheItemInterface $item): static;
194
+
195
+	/**
196
+	 * Returns true if the item exists, is attached and the Spl Hash matches
197
+	 * Returns false if the item exists, is attached and the Spl Hash mismatches
198
+	 * Returns null if the item does not exist
199
+	 *
200
+	 * @param CacheItemInterface $item
201
+	 * @return bool
202
+	 * @throws PhpfastcacheLogicException
203
+	 */
204
+	public function isAttached(CacheItemInterface $item): bool;
205
+
206
+	/**
207
+	 * Persists a cache item immediately.
208
+	 *
209
+	 * @param ExtendedCacheItemInterface|CacheItemInterface $item
210
+	 *   The cache item to save.
211
+	 *
212
+	 * @return bool
213
+	 *   True if the item was successfully persisted. False if there was an error.
214
+	 */
215
+	public function save(ExtendedCacheItemInterface|CacheItemInterface $item): bool;
216
+
217
+	/**
218
+	 * Save multiple items, possible uses:
219
+	 *  saveMultiple([$item1, $item2, $item3]);
220
+	 *  saveMultiple($item1, $item2, $item3);
221
+	 *
222
+	 * @param ExtendedCacheItemInterface[] $items
223
+	 * @return bool
224
+	 */
225
+	public function saveMultiple(ExtendedCacheItemInterface ...$items): bool;
226
+
227
+	/**
228
+	 * @return DriverIO
229
+	 */
230
+	public function getIO(): DriverIO;
231 231
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -212,7 +212,7 @@
 block discarded – undo
212 212
      * @return bool
213 213
      *   True if the item was successfully persisted. False if there was an error.
214 214
      */
215
-    public function save(ExtendedCacheItemInterface|CacheItemInterface $item): bool;
215
+    public function save(ExtendedCacheItemInterface | CacheItemInterface $item): bool;
216 216
 
217 217
     /**
218 218
      * Save multiple items, possible uses:
Please login to merge, or discard this patch.