@@ -125,59 +125,118 @@ public function discover(): Collection
125
125
protected function loadPlugin (string $ path ): ?array
126
126
{
127
127
$ manifestPath = "{$ path }/plugin.json " ;
128
+ $ pluginDir = basename ($ path );
128
129
129
130
if (! File::exists ($ manifestPath )) {
130
- Log::warning ("Plugin manifest not found: {$ manifestPath }" );
131
+ $ error = "Plugin manifest not found: {$ manifestPath }" ;
132
+ Log::error ($ error );
131
133
132
- return null ;
134
+ return [
135
+ 'id ' => $ pluginDir ,
136
+ 'name ' => $ pluginDir ,
137
+ 'path ' => $ path ,
138
+ 'error ' => $ error ,
139
+ 'enabled ' => false ,
140
+ ];
133
141
}
134
142
135
143
Log::debug ("Loading plugin from: {$ path }" );
136
144
137
145
try {
138
146
$ manifest = $ this ->readManifest ($ manifestPath );
139
147
if (! $ manifest ) {
140
- Log::warning ("Plugin at {$ path } is missing plugin.json " );
141
-
142
- return null ;
148
+ $ error = "Plugin at {$ path } has an invalid plugin.json file " ;
149
+ Log::warning ($ error );
150
+
151
+ return [
152
+ 'id ' => $ pluginDir ,
153
+ 'name ' => $ pluginDir ,
154
+ 'path ' => $ path ,
155
+ 'error ' => $ error ,
156
+ 'enabled ' => false ,
157
+ ];
143
158
}
144
159
145
160
if (! isset ($ manifest ['namespace ' ]) || ! isset ($ manifest ['provider ' ])) {
146
- Log::warning ("Plugin at {$ path } is missing required fields in plugin.json " );
147
-
148
- return null ;
161
+ $ error = 'Plugin is missing required fields in plugin.json (namespace and provider are required) ' ;
162
+ Log::warning ("Plugin at {$ path }: {$ error }" );
163
+
164
+ return [
165
+ 'id ' => $ manifest ['id ' ] ?? $ pluginDir ,
166
+ 'name ' => $ manifest ['name ' ] ?? $ pluginDir ,
167
+ 'path ' => $ path ,
168
+ 'manifest ' => $ manifest ,
169
+ 'error ' => $ error ,
170
+ 'enabled ' => false ,
171
+ ];
149
172
}
150
173
151
174
if (! isset ($ manifest ['id ' ])) {
152
- Log::warning ("Plugin manifest missing required 'id' field: {$ manifestPath }" );
153
-
154
- return null ;
175
+ $ error = "Plugin manifest missing required 'id' field " ;
176
+ Log::warning ("{$ manifestPath }: {$ error }" );
177
+
178
+ return [
179
+ 'id ' => $ pluginDir ,
180
+ 'name ' => $ manifest ['name ' ] ?? $ pluginDir ,
181
+ 'path ' => $ path ,
182
+ 'manifest ' => $ manifest ,
183
+ 'error ' => $ error ,
184
+ 'enabled ' => $ manifest ['enabled ' ] ?? false ,
185
+ ];
155
186
}
156
187
157
188
$ providerClass = $ manifest ['provider ' ];
158
- $ namespace = rtrim ($ manifest ['namespace ' ] ?? basename ( $ path ) , '\\' ).'\\' ;
189
+ $ namespace = rtrim ($ manifest ['namespace ' ], '\\' ).'\\' ;
159
190
160
191
$ this ->registerPluginAutoloading ($ namespace , $ path );
161
192
162
193
if (! class_exists ($ providerClass )) {
163
- Log::warning ("Plugin provider class not found: {$ providerClass } in {$ path }" );
164
-
165
- return null ;
194
+ $ error = "Provider class not found: {$ providerClass }" ;
195
+ Log::warning ("Plugin {$ manifest ['id ' ]}: {$ error }" );
196
+
197
+ return [
198
+ 'id ' => $ manifest ['id ' ],
199
+ 'name ' => $ manifest ['name ' ] ?? $ pluginDir ,
200
+ 'path ' => $ path ,
201
+ 'namespace ' => $ namespace ,
202
+ 'manifest ' => $ manifest ,
203
+ 'provider ' => $ providerClass ,
204
+ 'error ' => $ error ,
205
+ 'enabled ' => $ manifest ['enabled ' ] ?? false ,
206
+ ];
166
207
}
167
208
168
209
return [
169
210
'id ' => $ manifest ['id ' ],
170
- 'name ' => $ manifest ['name ' ] ?? basename ( $ path ) ,
211
+ 'name ' => $ manifest ['name ' ] ?? $ pluginDir ,
171
212
'path ' => $ path ,
172
213
'namespace ' => $ namespace ,
173
214
'manifest ' => $ manifest ,
174
215
'provider ' => $ providerClass ,
175
216
'enabled ' => $ manifest ['enabled ' ] ?? true ,
176
217
];
177
218
} catch (\JsonException $ e ) {
178
- Log::error ("Failed to parse plugin manifest: {$ manifestPath } - " .$ e ->getMessage ());
219
+ $ error = 'Failed to parse plugin manifest: ' .$ e ->getMessage ();
220
+ Log::error ("{$ manifestPath }: {$ error }" );
179
221
180
- return null ;
222
+ return [
223
+ 'id ' => $ pluginDir ,
224
+ 'name ' => $ pluginDir ,
225
+ 'path ' => $ path ,
226
+ 'error ' => $ error ,
227
+ 'enabled ' => false ,
228
+ ];
229
+ } catch (\Exception $ e ) {
230
+ $ error = 'Error loading plugin: ' .$ e ->getMessage ();
231
+ Log::error ("{$ path }: {$ error }" );
232
+
233
+ return [
234
+ 'id ' => $ pluginDir ,
235
+ 'name ' => $ pluginDir ,
236
+ 'path ' => $ path ,
237
+ 'error ' => $ error ,
238
+ 'enabled ' => false ,
239
+ ];
181
240
}
182
241
}
183
242
@@ -394,7 +453,10 @@ protected function readManifest(string $manifestPath): ?array
394
453
}
395
454
396
455
/**
397
- * Check if a plugin is enabled by its ID
456
+ * Check if a plugin is enabled and valid.
457
+ *
458
+ * @param string $pluginId The plugin ID to check
459
+ * @return bool True if the plugin is enabled and valid, false otherwise
398
460
*/
399
461
public function isPluginEnabled (string $ pluginId ): bool
400
462
{
@@ -403,12 +465,28 @@ public function isPluginEnabled(string $pluginId): bool
403
465
return false ;
404
466
}
405
467
468
+ if (isset ($ plugin ['error ' ])) {
469
+ return false ;
470
+ }
471
+
472
+ // Check if provider exists and is valid
473
+ if (! isset ($ plugin ['provider ' ]) || empty ($ plugin ['provider ' ])) {
474
+ return false ;
475
+ }
476
+
477
+ if (! class_exists ($ plugin ['provider ' ])) {
478
+ Log::warning ("Plugin provider class not found: {$ plugin ['provider ' ]}" );
479
+
480
+ return false ;
481
+ }
482
+
406
483
$ manifestPath = $ plugin ['path ' ].'/plugin.json ' ;
407
484
408
485
try {
409
486
$ manifest = $ this ->readManifest ($ manifestPath );
410
487
411
- return $ manifest ? ($ manifest ['enabled ' ] ?? true ) : false ;
488
+ return $ manifest ? (bool ) ($ manifest ['enabled ' ] ?? true ) : false ;
489
+
412
490
} catch (\RuntimeException $ e ) {
413
491
Log::error ('Error reading plugin manifest ' , [
414
492
'plugin ' => $ pluginId ,
@@ -429,13 +507,15 @@ public function registerPlugins(): void
429
507
Log::debug ("Registered plugin service provider: {$ plugin ['provider ' ]}" );
430
508
} catch (\Exception $ e ) {
431
509
Log::error ('Failed to register plugin service provider ' , [
432
- 'provider ' => $ plugin ['provider ' ] ?? 'unknown ' ,
510
+ 'plugin ' => $ plugin ['id ' ],
511
+ 'provider ' => $ plugin ['provider ' ],
433
512
'error ' => $ e ->getMessage (),
434
513
]);
435
514
throw $ e ;
436
515
}
437
516
} else {
438
- Log::debug ("Skipping disabled plugin: {$ plugin ['id ' ]}" );
517
+ $ reason = isset ($ plugin ['error ' ]) ? "error: {$ plugin ['error ' ]}" : 'disabled ' ;
518
+ Log::debug ("Skipping plugin {$ plugin ['id ' ]}: {$ reason }" );
439
519
}
440
520
});
441
521
}
0 commit comments