| Total Complexity | 5 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class FileCachePathBuilder |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * FileCachePathBuilder constructor. |
||
| 17 | * |
||
| 18 | * @param FileCacheManager $fileManager |
||
| 19 | * @param string $baseDir |
||
| 20 | */ |
||
| 21 | public function __construct(private FileCacheManager $fileManager, private string $baseDir) |
||
| 22 | { |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Builds the full path for a cache item based on its key and namespace. |
||
| 27 | * |
||
| 28 | * @param string $cacheKey |
||
| 29 | * @param string $namespace |
||
| 30 | * @return string |
||
| 31 | * @throws CacheFileException |
||
| 32 | */ |
||
| 33 | public function build(string $cacheKey, string $namespace = ''): string |
||
| 34 | { |
||
| 35 | $dir = $this->namespaceDir($namespace); |
||
| 36 | if (!empty($namespace)) { |
||
| 37 | $this->fileManager->createDirectory($dir); |
||
| 38 | } |
||
| 39 | return $dir . md5($cacheKey) . '.cache'; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Builds the directory path for a given namespace. |
||
| 44 | * |
||
| 45 | * @param string $namespace |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | public function namespaceDir(string $namespace = ''): string |
||
| 53 | } |
||
| 54 | } |
||
| 55 |