forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptimizeClearCommand.php
83 lines (72 loc) · 2.06 KB
/
OptimizeClearCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace Illuminate\Foundation\Console;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputOption;
#[AsCommand(name: 'optimize:clear')]
class OptimizeClearCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'optimize:clear';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Remove the cached bootstrap files';
/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->components->info('Clearing cached bootstrap files.');
$exceptions = Collection::wrap(explode(',', $this->option('except') ?? ''))
->map(fn ($except) => trim($except))
->filter()
->unique()
->flip();
$tasks = Collection::wrap($this->getOptimizeClearTasks())
->reject(fn ($command, $key) => $exceptions->hasAny([$command, $key]))
->toArray();
foreach ($tasks as $description => $command) {
$this->components->task($description, fn () => $this->callSilently($command) == 0);
}
$this->newLine();
}
/**
* Get the commands that should be run to clear the "optimization" files.
*
* @return array
*/
public function getOptimizeClearTasks()
{
return [
'cache' => 'cache:clear',
'compiled' => 'clear-compiled',
'config' => 'config:clear',
'events' => 'event:clear',
'routes' => 'route:clear',
'views' => 'view:clear',
...ServiceProvider::$optimizeClearCommands,
];
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getOptions()
{
return [
['except', 'e', InputOption::VALUE_OPTIONAL, 'The commands to skip'],
];
}
}