From ea747b0034bab34a3fa3a3f60dcdccd64196a91a Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Sun, 1 Dec 2024 12:44:55 +0100 Subject: [PATCH] feat: use sys_get_temp_dir as DefaultCacheDir --- .../ClassResolver/Cache/GacelaFileCache.php | 2 +- src/Framework/Config/Config.php | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Framework/ClassResolver/Cache/GacelaFileCache.php b/src/Framework/ClassResolver/Cache/GacelaFileCache.php index dc2a740f..8a7c8f0a 100644 --- a/src/Framework/ClassResolver/Cache/GacelaFileCache.php +++ b/src/Framework/ClassResolver/Cache/GacelaFileCache.php @@ -12,7 +12,7 @@ final class GacelaFileCache public const DEFAULT_ENABLED_VALUE = false; - public const DEFAULT_DIRECTORY_VALUE = '/.gacela/cache'; + public const DEFAULT_DIRECTORY_VALUE = null; private static ?bool $isEnabled = null; diff --git a/src/Framework/Config/Config.php b/src/Framework/Config/Config.php index 2426dc78..4d11d301 100644 --- a/src/Framework/Config/Config.php +++ b/src/Framework/Config/Config.php @@ -125,9 +125,7 @@ public function getCacheDir(): string return $this->cacheDir; } - $this->cacheDir = getenv('GACELA_CACHE_DIR') ?: $this->getAppRootDir() - . DIRECTORY_SEPARATOR - . ltrim($this->setup->getFileCacheDirectory(), DIRECTORY_SEPARATOR); + $this->cacheDir = getenv('GACELA_CACHE_DIR') ?: $this->getDefaultCacheDir(); return rtrim($this->cacheDir, DIRECTORY_SEPARATOR); } @@ -157,6 +155,17 @@ public function hasKey(string $key): bool return array_key_exists($key, $this->config); } + private function getDefaultCacheDir(): string + { + if ($this->setup->getFileCacheDirectory() === '') { + return sys_get_temp_dir(); + } + + return $this->getAppRootDir() + . DIRECTORY_SEPARATOR + . ltrim($this->setup->getFileCacheDirectory(), DIRECTORY_SEPARATOR); + } + /** * @return array */