-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPanicDevsModuleResolver.php
More file actions
158 lines (139 loc) · 3.64 KB
/
PanicDevsModuleResolver.php
File metadata and controls
158 lines (139 loc) · 3.64 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
declare(strict_types=1);
namespace PanicDevs\Modulite\Services\ModuleResolvers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Collection;
use PanicDevs\Modules\Services\ModuleService;
use PanicDevs\Modulite\Contracts\ModuleResolverInterface;
use Throwable;
/**
* Module resolver for panicdevs/modules package.
*
* This resolver integrates with the panicdevs/modules package
* to discover enabled modules for Modulite component discovery.
*
* @package PanicDevs\Modulite\Services\ModuleResolvers
*/
class PanicDevsModuleResolver implements ModuleResolverInterface
{
/**
* Application instance.
*/
protected Application $app;
/**
* Module service instance.
*/
protected ?ModuleService $moduleService = null;
/**
* Create a new PanicDevsModuleResolver instance.
*
* @param Application $app Application instance
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Get collection of enabled module names.
*
* @return Collection<int, string> Collection of module names
*/
public function getEnabledModules(): Collection
{
if (!$this->isAvailable())
{
return collect();
}
try
{
$modules = $this->getModuleService()->getEnabledByPriority();
return collect($modules)->pluck('name');
} catch (Throwable $e)
{
// Log error if needed
return collect();
}
}
/**
* Check if a specific module is enabled.
*
* @param string $moduleName Module name to check
* @return bool True if module is enabled, false otherwise
*/
public function isModuleEnabled(string $moduleName): bool
{
if (!$this->isAvailable())
{
return false;
}
try
{
return $this->getModuleService()->isEnabled($moduleName);
} catch (Throwable $e)
{
return false;
}
}
/**
* Get all available modules (enabled and disabled).
*
* @return Collection<int, string> Collection of all module names
*/
public function getAllModules(): Collection
{
if (!$this->isAvailable())
{
return collect();
}
try
{
$modules = $this->getModuleService()->getAll();
return collect($modules)->pluck('name');
} catch (Throwable $e)
{
return collect();
}
}
/**
* Get the module system name/type.
*
* @return string Module system identifier
*/
public function getSystemType(): string
{
return 'panicdevs';
}
/**
* Check if the module system is available and properly configured.
*
* @return bool True if system is available, false otherwise
*/
public function isAvailable(): bool
{
return class_exists(ModuleService::class) &&
$this->app->bound(ModuleService::class);
}
/**
* Get the module service instance.
*
* @return ModuleService
*/
protected function getModuleService(): ModuleService
{
if (null === $this->moduleService)
{
$this->moduleService = $this->app->make(ModuleService::class);
}
return $this->moduleService;
}
/**
* Determine whether panels should be registered
* before Filament initialization.
*
* @return bool True if panels must be registered before Filament
*/
public function shouldRegisterPanelsBeforeFilament(): bool
{
return false;
}
}