@@ -8,7 +8,7 @@ public function __construct(
88 }
99
1010 public function getData (string $ name ):mixed {
11- $ filePath = " $ this ->dirPath / $ name" ;
11+ $ filePath = $ this ->getFilePath ( $ name) ;
1212 if (!is_file ($ filePath )) {
1313 throw new FileNotFoundException ($ filePath );
1414 }
@@ -18,15 +18,15 @@ public function getData(string $name):mixed {
1818 }
1919
2020 public function setData (string $ name , mixed $ value ):void {
21- $ filePath = " $ this ->dirPath / $ name" ;
21+ $ filePath = $ this ->getFilePath ( $ name) ;
2222 if (!is_dir (dirname ($ filePath ))) {
2323 mkdir (dirname ($ filePath ), 0775 , true );
2424 }
2525 file_put_contents ($ filePath , serialize ($ value ));
2626 }
2727
2828 public function checkValidity (string $ name , int $ secondsValidity ):void {
29- $ filePath = " $ this ->dirPath / $ name" ;
29+ $ filePath = $ this ->getFilePath ( $ name) ;
3030 if (!is_file ($ filePath )) {
3131 throw new CacheInvalidException ("$ filePath (does not exist) " );
3232 }
@@ -37,11 +37,16 @@ public function checkValidity(string $name, int $secondsValidity):void {
3737 }
3838
3939 public function invalidate (string $ name ):void {
40- $ filePath = " $ this ->dirPath / $ name" ;
40+ $ filePath = $ this ->getFilePath ( $ name) ;
4141 if (!is_file ($ filePath )) {
4242 return ;
4343 }
4444
4545 unlink ($ filePath );
4646 }
47+
48+ private function getFilePath (string $ name ):string {
49+ $ escapedName = rawurlencode ($ name );
50+ return "$ this ->dirPath / $ escapedName " ;
51+ }
4752}
0 commit comments