From f4f1e2248ff329a68eb1192c5796ff738aec9015 Mon Sep 17 00:00:00 2001 From: Mert Date: Sun, 10 Mar 2024 22:13:04 +0300 Subject: [PATCH 1/3] adds extra conditions --- src/CloudflareCache.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/CloudflareCache.php b/src/CloudflareCache.php index 6d108ef..dec8058 100644 --- a/src/CloudflareCache.php +++ b/src/CloudflareCache.php @@ -95,6 +95,17 @@ public function purgeByUrls(array $urls): bool|string public function isEnabled(): bool { + if (app()->runningUnitTests()) { + return true; + } + + if (! config('cloudflare-cache.api_email') + || ! config('cloudflare-cache.api_key') + || ! config('cloudflare-cache.identifier') + ) { + return false; + } + if (config('cloudflare-cache.debug')) { return true; } From b0d3a9836638ae1ebba93c4168d4541b050b46c5 Mon Sep 17 00:00:00 2001 From: Mert Date: Sun, 10 Mar 2024 22:13:55 +0300 Subject: [PATCH 2/3] rename isEnabled method to isActive --- src/CloudflareCache.php | 2 +- src/CloudflarePagesMiddleware.php | 2 +- src/Facades/CloudflareCache.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CloudflareCache.php b/src/CloudflareCache.php index dec8058..19d4dd2 100644 --- a/src/CloudflareCache.php +++ b/src/CloudflareCache.php @@ -93,7 +93,7 @@ public function purgeByUrls(array $urls): bool|string ]); } - public function isEnabled(): bool + public function isActive(): bool { if (app()->runningUnitTests()) { return true; diff --git a/src/CloudflarePagesMiddleware.php b/src/CloudflarePagesMiddleware.php index eb83748..1cb128f 100644 --- a/src/CloudflarePagesMiddleware.php +++ b/src/CloudflarePagesMiddleware.php @@ -61,7 +61,7 @@ public function shouldCacheResponse(Request $request, Response $response): bool return false; } - if (! CloudflareCacheFacade::isEnabled() && ! app()->runningUnitTests()) { + if (! CloudflareCacheFacade::isActive() && ! app()->runningUnitTests()) { return false; } diff --git a/src/Facades/CloudflareCache.php b/src/Facades/CloudflareCache.php index 79cab29..ae3c3bd 100644 --- a/src/Facades/CloudflareCache.php +++ b/src/Facades/CloudflareCache.php @@ -8,7 +8,7 @@ /** * @see \Yediyuz\CloudflareCache\CloudflareCache * - * @method static bool isEnabled() + * @method static bool isActive() * @method static bool|string purgeEverything() * @method static bool|string purgeByPrefixes(array $prefixes) * @method static bool|string purgeByTags(array $tags) From fe9f260e2e7bc23c586136a755e4c4418ff7c551 Mon Sep 17 00:00:00 2001 From: Mert Date: Sun, 10 Mar 2024 22:15:13 +0300 Subject: [PATCH 3/3] wip --- src/Services/CloudflareService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Services/CloudflareService.php b/src/Services/CloudflareService.php index 64d31d1..9991b3f 100644 --- a/src/Services/CloudflareService.php +++ b/src/Services/CloudflareService.php @@ -11,9 +11,9 @@ class CloudflareService implements CloudflareServiceInterface { public function __construct( private readonly Factory $client, - private readonly string $apiEmail, - private readonly string $apiKey, - private readonly string $identifier, + private readonly ?string $apiEmail, + private readonly ?string $apiKey, + private readonly ?string $identifier, ) { // . }