@@ -337,9 +337,7 @@ protected function registerPluginsInPanel(array $pluginClasses, string $panelPat
337337 $ pluginsToAdd = [];
338338
339339 foreach ($ pluginClasses as $ pluginClass ) {
340- $ escapedPluginClass = preg_quote ($ pluginClass , '/ ' );
341- if (str_contains ($ content , $ pluginClass ) ||
342- preg_match ('/->plugin\([^)]* ' .$ escapedPluginClass .'[^)]*\)/ ' , $ content )) {
340+ if ($ this ->isPluginAlreadyRegistered ($ pluginClass , $ content )) {
343341 note ("Plugin already registered: {$ pluginClass }" );
344342
345343 continue ;
@@ -413,4 +411,39 @@ protected function registerPluginsInPanel(array $pluginClasses, string $panelPat
413411 info ('Plugins registered in panel ' );
414412 }
415413 }
414+
415+ /**
416+ * Check if a plugin is already registered in the panel file.
417+ * Checks both the full namespace and the short class name (if used with 'use' statement).
418+ */
419+ protected function isPluginAlreadyRegistered (string $ pluginClass , string $ content ): bool
420+ {
421+ // Check for full namespace
422+ $ escapedPluginClass = preg_quote ($ pluginClass , '/ ' );
423+ if (str_contains ($ content , $ pluginClass ) ||
424+ preg_match ('/->plugin\([^)]* ' .$ escapedPluginClass .'[^)]*\)/ ' , $ content )) {
425+ return true ;
426+ }
427+
428+ // Extract short class name (e.g., "DraftPlugin" from "Moox\Draft\DraftPlugin")
429+ $ parts = explode ('\\' , $ pluginClass );
430+ $ shortClassName = end ($ parts );
431+
432+ // Check if there's a 'use' statement for this class
433+ $ escapedFullClass = preg_quote ($ pluginClass , '/ ' );
434+ $ usePattern = '/use\s+ ' .$ escapedFullClass .'\s*;/ ' ;
435+
436+ if (preg_match ($ usePattern , $ content )) {
437+ // If 'use' statement exists, check for short class name in plugin registration
438+ $ escapedShortName = preg_quote ($ shortClassName , '/ ' );
439+ if (preg_match ('/->plugins?\s*\(\s*\[[^\]]* ' .$ escapedShortName .'[^\]]*\]/ ' , $ content ) ||
440+ preg_match ('/->plugin\s*\(\s*[^)]* ' .$ escapedShortName .'[^)]*\)/ ' , $ content ) ||
441+ str_contains ($ content , $ shortClassName .'::make() ' ) ||
442+ str_contains ($ content , $ shortClassName .'::class ' )) {
443+ return true ;
444+ }
445+ }
446+
447+ return false ;
448+ }
416449}
0 commit comments