Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename isEnabled method to isActive #9

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
21 changes: 16 additions & 5 deletions src/CloudflareCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

class CloudflareCache implements CloudflareCacheInterface
{
public const TAGS_ATTR = 'cloudflare_cache_tags';
public const TAGS_ATTR = 'cloudflare-cache-tags';

public const TTL_ATTR = 'cloudflare_cache_ttl';
public const TTL_ATTR = 'cloudflare-cache-ttl';

public function __construct(private readonly CloudflareServiceInterface $service)
{
Expand All @@ -23,7 +23,7 @@ public function __construct(private readonly CloudflareServiceInterface $service
*/
public static function getIgnoredMiddlewares(): array
{
return Arr::where(config('cloudflare_cache.ignored_middlewares', []), static fn ($middleware) => class_exists($middleware));
return Arr::where(config('cloudflare-cache.ignored_middlewares', []), static fn ($middleware) => class_exists($middleware));
}

/**
Expand Down Expand Up @@ -93,9 +93,20 @@ public function purgeByUrls(array $urls): bool|string
]);
}

public function isEnabled(): bool
public function isActive(): bool
{
if (config('cloudflare_cache.debug')) {
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;
}

Expand Down
14 changes: 7 additions & 7 deletions src/CloudflareCacheServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CloudflareCacheServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
$package->name('cloudflare_cache')
$package->name('cloudflare-cache')
->hasConfigFile()
->hasCommand(CloudflareCacheCommand::class);
}
Expand All @@ -37,16 +37,16 @@ public function packageRegistered(): void

public function registerClient(): static
{
$this->app->bind('cloudflare_cache.client', function ($app): Factory {
$this->app->bind('cloudflare-cache.client', function ($app): Factory {
return $app[Factory::class];
});

$this->app->singleton(CloudflareServiceInterface::class, function ($app): CloudflareService {
return new CloudflareService(
$app->make('cloudflare_cache.client'),
config('cloudflare_cache.api_email'),
config('cloudflare_cache.api_key'),
config('cloudflare_cache.identifier'),
$app->make('cloudflare-cache.client'),
config('cloudflare-cache.api_email'),
config('cloudflare-cache.api_key'),
config('cloudflare-cache.identifier'),
);
});

Expand All @@ -61,6 +61,6 @@ public function registerCloudflareCache(): void
);
});

$this->app->alias(CloudflareCacheInterface::class, 'cloudflare_cache');
$this->app->alias(CloudflareCacheInterface::class, 'cloudflare-cache');
}
}
2 changes: 1 addition & 1 deletion src/CloudflarePagesMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function getCacheTTL(Request $request): int
return $request->attributes->get(CloudflareCache::TTL_ATTR);
}

return config('cloudflare_cache.default_cache_ttl') ?? 600;
return config('cloudflare-cache.cache_ttl') ?? 600;
}

public function shouldCacheResponse(Request $request, Response $response): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CloudflareCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CloudflareCacheCommand extends Command
{
public $signature = 'laravel-cloudflare-cache';
public $signature = 'cloudflare-cache';

public $description = 'My command';

Expand Down
2 changes: 1 addition & 1 deletion src/Facades/CloudflareCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ class CloudflareCache extends Facade
{
protected static function getFacadeAccessor(): string
{
return 'cloudflare_cache';
return 'cloudflare-cache';
}
}
8 changes: 4 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function getEnvironmentSetUp($app): void
config()->set('app.key', 'base64:' . base64_encode(Encrypter::generateKey(config()['app.cipher'])));
config()->set('database.default', 'testing');

config()->set('cloudflare_cache.api_email', '');
config()->set('cloudflare_cache.api_key', '');
config()->set('cloudflare_cache.identifier', '');
config()->set('cloudflare-cache.api_email', '');
config()->set('cloudflare-cache.api_key', '');
config()->set('cloudflare-cache.identifier', '');
}

protected function registerTestRoutes(): void
Expand Down Expand Up @@ -67,7 +67,7 @@ protected function registerTestRoutes(): void
};

Route::middleware('web')
->name('cloudflare_cache.')
->name('cloudflare-cache.')
->group(function () use ($routes) {
$routes();
});
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/CloudflarePagesMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

test('cache bulunmayan sayfalarda session cookie mevcut olmalıdır', function () {
$response = $this->get(route('cloudflare_cache.home'));
$response = $this->get(route('cloudflare-cache.home'));

$response->assertCookie('XSRF-TOKEN');
$response->assertCookie('laravel_session');
Expand All @@ -16,8 +16,8 @@
$response->assertCookieMissing('XSRF-TOKEN');
$response->assertCookieMissing('laravel_session');
})->with([
'cloudflare_cache.content_without_tags',
'cloudflare_cache.content_in_args',
'cloudflare_cache.content_in_array',
'cloudflare_cache.content_in_closure',
'cloudflare-cache.content_without_tags',
'cloudflare-cache.content_in_args',
'cloudflare-cache.content_in_array',
'cloudflare-cache.content_in_closure',
]);
Loading