Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fuelviews/laravel-cloudflare-cache
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.1-RC1
Choose a base ref
...
head repository: fuelviews/laravel-cloudflare-cache
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.0.1
Choose a head ref
  • 1 commit
  • 6 files changed
  • 2 contributors

Commits on Apr 2, 2024

  1. Refactored CloudflareCache class, added a new console command to purg… (

    #2)
    
    * Refactored CloudflareCache class, added a new console command to purge everything, and updated configuration keys for the Cloudflare API.
    
    * Fix styling
    
    * Refactor config file to use more descriptive variable names and add comments for clarity.
    
    ---------
    
    Co-authored-by: thejmitchener <thejmitchener@users.noreply.github.com>
    thejmitchener and thejmitchener authored Apr 2, 2024
    Copy the full SHA
    f7c7721 View commit details
Showing with 60 additions and 17 deletions.
  1. +18 −9 README.md
  2. +7 −4 config/cloudflare-cache.php
  3. +2 −2 src/CloudflareCache.php
  4. +4 −1 src/CloudflareCacheServiceProvider.php
  5. +29 −0 src/Commands/CloudflareCacheClearCommand.php
  6. +0 −1 src/Facades/CloudflareCache.php
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -24,32 +24,41 @@ php artisan vendor:publish --tag="cloudflare-cache-config"
This is the contents of the published config file:

```php
<?php

return [
/**
* Generate global api key.
* Generate zone or global api key.
*
* @see https://dash.cloudflare.com/profile/api-tokens
*/
'api_key' => env('CLOUDFLARE_CACHE_KEY'),
'api_key' => env('CLOUDFLARE_CACHE_API_KEY'),

/**
* zone_id of your site on cloudflare dashboard.
* The zone_id of your site on cloudflare dashboard.
*/
'identifier' => env('CLOUDFLARE_CACHE_IDENTIFIER'),
'identifier' => env('CLOUDFLARE_CACHE_ZONE_ID'),

'debug' => env('CLOUDFLARE_CACHE_DEBUG', false),
/**
* Debug mode.
*/
'debug' => env('CLOUDFLARE_CACHE_DEBUG', false),
];

```

## Usage

Purges everything
Purge everything function with:

```php
CloudflareCache::purgeEverything()
use Fuelviews\CloudflareCache\Facades\CloudflareCache;

CloudflareCache::purgeEverything();
```

Purge everything console command with:

```bash
php artisan cloudflare-cache:clear
```

## Testing
11 changes: 7 additions & 4 deletions config/cloudflare-cache.php
Original file line number Diff line number Diff line change
@@ -2,16 +2,19 @@

return [
/**
* Generate global api key.
* Generate zone or global api key.
*
* @see https://dash.cloudflare.com/profile/api-tokens
*/
'api_key' => env('CLOUDFLARE_CACHE_KEY'),
'api_key' => env('CLOUDFLARE_CACHE_API_KEY'),

/**
* zone_id of your site on cloudflare dashboard.
* The zone_id of your site on cloudflare dashboard.
*/
'identifier' => env('CLOUDFLARE_CACHE_IDENTIFIER'),
'identifier' => env('CLOUDFLARE_CACHE_ZONE_ID'),

/**
* Debug mode.
*/
'debug' => env('CLOUDFLARE_CACHE_DEBUG', false),
];
4 changes: 2 additions & 2 deletions src/CloudflareCache.php
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
{
public function __construct(private CloudflareServiceInterface $service)
{
// .
//
}

/**
@@ -39,7 +39,7 @@ public function purgeEverything(): bool|string
]);
}

public function isActive(): bool
public function ive(): bool
{
if (app()->runningUnitTests()) {
return true;
5 changes: 4 additions & 1 deletion src/CloudflareCacheServiceProvider.php
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

namespace Fuelviews\CloudflareCache;

use Fuelviews\CloudflareCache\Commands\CloudflareCacheClearCommand;
use Fuelviews\CloudflareCache\Services\CloudflareService;
use Fuelviews\CloudflareCache\Services\CloudflareServiceInterface;
use Illuminate\Http\Client\Factory;
@@ -14,7 +15,9 @@ public function configurePackage(Package $package): void
{
$package
->name('laravel-cloudflare-cache')
->hasConfigFile();
->hasConfigFile()
->hasCommand(CloudflareCacheClearCommand::class,
);
}

public function packageRegistered(): void
29 changes: 29 additions & 0 deletions src/Commands/CloudflareCacheClearCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Fuelviews\CloudflareCache\Commands;

use Fuelviews\CloudflareCache\Facades\CloudflareCache;
use Illuminate\Console\Command;

class CloudflareCacheClearCommand extends Command
{
protected $signature = 'cloudflare-cache:clear';

protected $description = 'Cloudflare purge everything';

/**
* Execute the console command.
*
* This method handles the logic after the command is called. It decides
* whether to include an index in the sitemap based on configuration settings.
* Depending on those settings, it may generate individual sitemaps for pages
* and posts and then either create a sitemap index to include them or
* directly generate a single sitemap.
*/
public function handle(): bool
{
CloudflareCache::purgeEverything();

return true;
}
}
1 change: 0 additions & 1 deletion src/Facades/CloudflareCache.php
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
/**
* @see \Fuelviews\CloudflareCache\CloudflareCache
*
* @method static bool isActive()
* @method static bool|string purgeEverything()
*/
class CloudflareCache extends Facade