forked from doppar/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppBoostCommand.php
More file actions
73 lines (62 loc) · 1.88 KB
/
AppBoostCommand.php
File metadata and controls
73 lines (62 loc) · 1.88 KB
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
<?php
namespace Phaseolies\Console\Commands;
use Phaseolies\Support\Facades\Pool;
use Phaseolies\Console\Schedule\Command;
use RuntimeException;
class AppBoostCommand extends Command
{
/**
* The name of the console command.
*
* @var string
*/
protected $name = 'boost';
/**
* The description of the console command.
*
* @var string
*/
protected $description = 'Optimizes application performance by clearing and rebuilding caches';
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
return $this->executeWithTiming(function() {
$commands = [
'cache:clear', // Clear application cache
'route:clear', // Clear route cache
'route:cache', // Rebuild route cache
'config:clear', // Clear configuration cache
'config:cache', // Rebuild configuration cache
'view:clear', // Clear compiled views
'view:cache', // Recompile views
];
$this->line('<fg=yellow>⚡ Running application optimization commands:</>');
$this->newLine();
foreach ($commands as $command) {
$this->runCommand($command);
}
$this->newLine();
$this->displaySuccess('Application optimization completed successfully');
return Command::SUCCESS;
});
}
/**
* Run a command via Pool and output status.
*
* @param string $command
* @return void
* @throws RuntimeException
*/
protected function runCommand(string $command): void
{
$this->line(sprintf(
"<fg=blue>➜</> <fg=white>%s</>",
$command
));
Pool::call($command, false);
}
}