-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathModuleOptimizeCommand.php
More file actions
69 lines (56 loc) · 1.87 KB
/
ModuleOptimizeCommand.php
File metadata and controls
69 lines (56 loc) · 1.87 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
<?php
declare(strict_types=1);
namespace PanicDevs\Modules\Console;
use Illuminate\Console\Command;
use PanicDevs\Modules\ManifestBuilder;
/**
* ModuleOptimizeCommand
*
* Optimizes module loading by caching the module manifest.
* This command is automatically called by Laravel's `optimize` command.
*
* @package PanicDevs\Modules\Console
* @author PanicDevs
* @since 1.0.0
*/
class ModuleOptimizeCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'modules:cache
{--force : Force cache regeneration even if cache exists}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Cache the module manifest for better performance';
/**
* Execute the console command.
*/
public function handle(ManifestBuilder $manifestBuilder): int
{
$this->info('Caching module manifest...');
$cacheFile = base_path('bootstrap/cache/modules.php');
// Check if cache exists and force flag
if (!$this->option('force') && file_exists($cacheFile))
{
$this->info('Module cache already exists. Use --force to regenerate.');
return self::SUCCESS;
}
// Clear existing cache first
$manifestBuilder->clear();
// Build and cache the manifest
$modules = $manifestBuilder->build();
$enabledCount = count(array_filter($modules, fn($module) => $module['enabled']));
$totalCount = count($modules);
$this->info("Module manifest cached successfully!");
$this->line("- <fg=green>{$enabledCount}</> enabled modules");
$this->line("- <fg=yellow>{$totalCount}</> total modules");
$this->line("- Cache file: <fg=blue>{$cacheFile}</>");
return self::SUCCESS;
}
}