55use ByJG \Cache \CacheLockInterface ;
66use DateInterval ;
77use Exception ;
8+ use Psr \Container \ContainerExceptionInterface ;
9+ use Psr \Container \NotFoundExceptionInterface ;
10+ use Psr \Log \LoggerInterface ;
811use Psr \Log \NullLogger ;
12+ use Psr \SimpleCache \InvalidArgumentException ;
913
1014class FileSystemCacheEngine extends BaseCacheEngine implements CacheLockInterface
1115{
1216
13- protected $ logger = null ;
17+ protected ? LoggerInterface $ logger = null ;
1418
15- protected $ prefix = null ;
16- protected $ path = null ;
19+ protected ? string $ prefix = null ;
20+ protected ? string $ path = null ;
1721
18- public function __construct ($ prefix = 'cache ' , $ path = null , $ logger = null )
22+ public function __construct (string $ prefix = 'cache ' , ? string $ path = null , ? LoggerInterface $ logger = null )
1923 {
2024 $ this ->prefix = $ prefix ;
2125 $ this ->path = $ path ?? sys_get_temp_dir ();
@@ -30,7 +34,9 @@ public function __construct($prefix = 'cache', $path = null, $logger = null)
3034 * @param string $key The object KEY
3135 * @param mixed $default IGNORED IN MEMCACHED.
3236 * @return mixed Description
33- * @throws \Psr\SimpleCache\InvalidArgumentException
37+ * @throws ContainerExceptionInterface
38+ * @throws NotFoundExceptionInterface
39+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
3440 */
3541 public function get (string $ key , mixed $ default = null ): mixed
3642 {
@@ -104,7 +110,7 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
104110
105111 $ validUntil = $ this ->addToNow ($ ttl );
106112 if (!empty ($ validUntil )) {
107- file_put_contents ($ fileKey . ".ttl " , $ validUntil );
113+ file_put_contents ($ fileKey . ".ttl " , ( string ) $ validUntil );
108114 }
109115 } catch (Exception $ ex ) {
110116 $ this ->logger ->warning ("[Filesystem cache] I could not write to cache on file ' " . basename ($ key ) . "'. Switching to nocache=true mode. " );
@@ -117,7 +123,6 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
117123 /**
118124 * @param string $key
119125 * @return bool
120- * @throws \Psr\SimpleCache\InvalidArgumentException
121126 */
122127 public function delete (string $ key ): bool
123128 {
@@ -146,7 +151,7 @@ public function lock(string $key): void
146151 * UnLock resource after set it.
147152 * @param string $key
148153 */
149- public function unlock ($ key ): void
154+ public function unlock (string $ key ): void
150155 {
151156
152157 $ this ->logger ->info ("[Filesystem cache] Unlock ' $ key' " );
@@ -158,12 +163,22 @@ public function unlock($key): void
158163 }
159164 }
160165
166+ /**
167+ * @throws ContainerExceptionInterface
168+ * @throws NotFoundExceptionInterface
169+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
170+ */
161171 public function isAvailable (): bool
162172 {
163173 return is_writable (dirname ($ this ->fixKey ('test ' )));
164174 }
165175
166- protected function fixKey ($ key )
176+ /**
177+ * @throws ContainerExceptionInterface
178+ * @throws NotFoundExceptionInterface
179+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
180+ */
181+ protected function fixKey (string $ key ): string
167182 {
168183 $ key = $ this ->getKeyFromContainer ($ key );
169184
@@ -177,6 +192,9 @@ protected function fixKey($key)
177192 * Wipes clean the entire cache's keys.
178193 *
179194 * @return bool True on success and false on failure.
195+ * @throws ContainerExceptionInterface
196+ * @throws NotFoundExceptionInterface
197+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
180198 */
181199 public function clear (): bool
182200 {
@@ -197,8 +215,9 @@ public function clear(): bool
197215 *
198216 * @param string $key The cache item key.
199217 * @return bool
200- * @throws \Psr\SimpleCache\InvalidArgumentException
201- * MUST be thrown if the $key string is not a legal value.
218+ * @throws ContainerExceptionInterface
219+ * @throws NotFoundExceptionInterface
220+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
202221 */
203222 public function has (string $ key ): bool
204223 {
0 commit comments