From 6c637cd24c7a9867c60a5bce70bd768577982d44 Mon Sep 17 00:00:00 2001 From: grandeljay Date: Tue, 14 Jun 2022 10:32:25 +0200 Subject: [PATCH] Create cache directory if it is missing --- src/classes/cache/cache.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/classes/cache/cache.php b/src/classes/cache/cache.php index 3647d949..dc2aa2ae 100644 --- a/src/classes/cache/cache.php +++ b/src/classes/cache/cache.php @@ -19,6 +19,7 @@ class Cache /** * Protected */ + protected string $url; protected string $directory = ROOT . '/src/cache'; protected int $maxAge = 2592000; // 30 days @@ -34,11 +35,16 @@ class Cache protected function write(mixed $value): void { - $filepath = $this->getFilepath(); - $directory = dirname($filepath); + $filepath = $this->getFilepath(); + $directoryName = dirname($filepath); + $directoryCache = dirname($directoryName); - if (false === file_exists($directory)) { - mkdir($directory); + if (false === file_exists($directoryCache)) { + mkdir($directoryCache); + } + + if (false === file_exists($directoryName)) { + mkdir($directoryName); } file_put_contents($filepath, json_encode($value)); @@ -47,8 +53,9 @@ class Cache /** * Public */ - public function __construct(protected string $url) + public function __construct($url) { + $this->url = trim($url); } public function exists(): bool