Skip to content

Commit e3fe087

Browse files
committed
Create the docs:clear-cache command
1 parent 0782791 commit e3fe087

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php namespace App\Console\Commands;
2+
3+
use Illuminate\Console\Command;
4+
use Illuminate\Filesystem\Filesystem;
5+
6+
class ClearPageCache extends Command
7+
{
8+
/**
9+
* The name of the console command.
10+
*
11+
* @var string
12+
*/
13+
protected $name = 'docs:clear-cache';
14+
15+
/**
16+
* The console command description.
17+
*
18+
* @var string
19+
*/
20+
protected $description = 'Clears the page cache.';
21+
22+
/**
23+
* Execute the console command.
24+
*
25+
* @return mixed
26+
*/
27+
public function handle()
28+
{
29+
$path = public_path('page-cache');
30+
31+
if ($this->clearDirectory($path)) {
32+
$this->info("Page cache directory cleared at {$path}.");
33+
} else {
34+
$this->warn("Page cache directory not cleared at {$path}.");
35+
}
36+
}
37+
38+
/**
39+
* Clear all contents of the given directory recursively.
40+
*
41+
* @param string $path
42+
* @return bool
43+
*/
44+
protected function clearDirectory($path)
45+
{
46+
return $this->laravel->make(Filesystem::class)->deleteDirectory($path, true);
47+
}
48+
}

app/Console/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Kernel extends ConsoleKernel
1111
* @var array
1212
*/
1313
protected $commands = [
14+
Commands\ClearPageCache::class,
1415
Commands\IndexDocumentation::class,
1516
];
1617

0 commit comments

Comments
 (0)