diff --git a/src/CloudflareCache.php b/src/CloudflareCache.php index 6d108ef..19d4dd2 100644 --- a/src/CloudflareCache.php +++ b/src/CloudflareCache.php @@ -93,8 +93,19 @@ public function purgeByUrls(array $urls): bool|string ]); } - public function isEnabled(): bool + public function isActive(): 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; } 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) 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, ) { // . }